#Problem with a gravity script
78 messages · Page 1 of 1 (latest)
yes
local part = script.Parent
part.Touched:Connect(function(touchPart)
local Humanoid = touchPart.Parent:FindFirstChild("Humanoid")
if Humanoid then
part.CanCollide = false
game.Workspace.Gravity = 50
end
end)
is this in the server or the client
this is the script modified , and it still doesn't work
can you please explain what is the difference between server and client? im new at scripting i apologize
client code only runs on the users machine
server runs for everything
is this under start character scripts
it is , and in a local script
where should i write .Workspace?
local character = script.Parent
local hrp = character:WaitForChild("HumanoidRootPart")
hrp.Touched:Connect(function(hit)
if hit.Name == "PartGravityOne" then
game.Workspace.Gravity = 192.2
if hit.Name == "PartGravityTwo" then
game.Workspace.Gravity = 50
if hit.Name == "PartGravityThree" then
game.Workspace.Gravity = 192.2
if hit.Name == "PartGravityFour" then
game.Workspace.Gravity = 300
end
end
end
end
end)
where in the script?
replace game.Workspace to workspace
oh right , now no errors in the code
i mean , no error but maybe the code doesn't work , i have to test it. thank you for the help if it doesn't work can i ask you again?
sure
only reason i suggest that is i know there is a difference between workspace and game.Workspace
Can I ask you a favor if you want?
i need another player for the test would you like to enter my game for a couple of minutes?
you can test it in studio
there is a test tab at the top
and a thingy that loads two players that you can control
search around for a second you will find it
oh
i see
now i try
thank you for the hint
omg 2 players hahahah
i test it , it doesn't work
** You are now Level 4! **
okay
is this used to see if the gravity change works? because it works
wait so its changing the gravity just on every player?
yes
weird
it works , it changes gravity but for all
send me your current script
local character = script.Parent
local hrp = character:WaitForChild("HumanoidRootPart")
hrp.Touched:Connect(function(hit)
if hit.Name == "PartGravityOne" then
workspace.Gravity = 192.2
if hit.Name == "PartGravityTwo" then
workspace.Gravity = 50
if hit.Name == "PartGravityThree" then
workspace.Gravity = 192.2
if hit.Name == "PartGravityFour" then
workspace.Gravity = 300
end
end
end
end
end)
this is inside the startercharacterscripts in a local script
hmmm
try putting it in starter player scripts
and instead of local character = script.Parent
do
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
how do u use this block for writing the script inside?
'''lua local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character
local hrp = Players:WaitForChild("HumanoidRootPart")
hrp.Touched:Connect(function(hit)
if hit.Name == "PartGravityOne" then
workspace.Gravity = 192.2
if hit.Name == "PartGravityTwo" then
workspace.Gravity = 50
if hit.Name == "PartGravityThree" then
workspace.Gravity = 192.2
if hit.Name == "PartGravityFour" then
workspace.Gravity = 300
end
end
end
end
end) '''
ehm
`` not "
i don't have these `` so i copy it
kk
local Player = Players.LocalPlayer
local Character = Player.Character
local hrp = Players:WaitForChild("HumanoidRootPart")
hrp.Touched:Connect(function(hit)
if hit.Name == "PartGravityOne" then
workspace.Gravity = 192.2
if hit.Name == "PartGravityTwo" then
workspace.Gravity = 50
if hit.Name == "PartGravityThree" then
workspace.Gravity = 192.2
if hit.Name == "PartGravityFour" then
workspace.Gravity = 300
end
end
end
end
end)```
so this is the script
i think i had a script like this that actually worked
lemme get on the right account and nab it
ill try and find it
ok thx
couldnt find it mustve been lost to time
i can help you tommorow but its 4 in the morning for me
sorry
no problem
alr hopefully we solve it eventually
-- Services
local Players = game:GetService("Players")
-- Player Vars
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
-- Funcs
local function GetPart(Hit)
if Hit.Name == "PartGravityOne" then
workspace.Gravity = 192.2
elseif Hit.Name == "PartGravityTwo" then
workspace.Gravity = 50
elseif Hit.Name == "PartGravityThree" then
workspace.Gravity = 192.2
elseif Hit.Name == "PartGravityFour" then
workspace.Gravity = 300
end
end
-- Loops
for Number, Descendent in pairs(Character:GetDescendants()) do
if Descendent:IsA("Part") or Descendent:IsA("MeshPart") then
Descendent.Touched:Connect(function(Hit)
GetPart(Hit)
end)
end
end
got a working script here, put it in starter character scripts
@lucid blaze
To explain what this does, instead of gettting the .Touched event from the part, it gets the .Touched event from any mesh part or part that is a descendant of the character. It then calls a function to see if the hit.Name is equal to any of the names specified in your previous scripts
and yes i did test it on two playes and it works perfectly