LocalScripts don’t run under non-client areas (like the workspace).
Even if it didn’t work, it would trigger the gravity-setting code even if the LocalPlayer wasn’t the one who triggered it, since it only looks for any generic Humanoid and not the LocalPlayer’s own one.
Ah yes I forgot we are trying to access the workspace, I’m slacking here.
local part = workspace:WaitForChild("Part")
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if workspace.Gravity ~= 10 then
workspace.Gravityy = 10 -- ur gravity here
end
end
end)
Better solution here, yet I’m unsure about having a bad side of changing the gravity everytime its touched, but I guess that’s better since we have multiple parts touching.
@Rainzyyy Try having this as a local script inside PlayerStarterScripts, should work perfectly.
local Gravity = workspace.Gravity assigns the value of the gravity to the variable, not the reference. Your script is just changing your own variable, doing nothing. If you replace the Gravity with workspace.Gravity throughout it will work perfectly for OP.
This returns a value, not a property. Changing it by doing Gravity = 10 won’t change the Gravity property of the workspace but rather the value of the variable. Additionally, as mentioned earlier, it would trigger the gravity-modifier on all clients since it doesn’t check that the humanoid in question belongs to the LocalPlayer.
Edit:
note: emojipasta already pointed out the first issue
Could you point out where I said “Negative gravity” in any of my messages? By reversing a force I mean many other applications other than gravity. You can have further control over your character just not for gravity using the same force. This argument is pointless so Ill move out.
This changes the gravity for everyone, I want it to only change for the person who touched the part.
local part = workspace:WaitForChild("Part")
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if workspace.Gravity ~= 10 then
workspace.Gravityy = 10 -- ur gravity here
end
end
end)
Put this in a LocalScript in StarterCharacterScripts:
local part = workspace:WaitForChild("Part")
part.Touched:Connect(function(hit)
if hit:IsDescendantOf(script.Parent) then
if workspace.Gravity ~= 10 then
workspace.Gravity = 10
end
end
end)
local part = workspace:WaitForChild("Part")
part.Touched:Connect(function(hit)
if (hit.Parent:FindFirstChildWhichIsA("Humanoid")) and (hit.Parent:FindFirstChild("Humanoid") == game.Players.LocalPlayer.Character:FindFirstChild("Humanoid")) then
if workspace.Gravity ~= 100 then
workspace.Gravity = 100-- your gravity here
end
end
end)
A simple way is to make an invisible block which the user touches and it changes their gravity.
debounce = true
function onTouched(hit)
local h = hit.Parent:findFirstChild(“Humanoid”)
if (h ~= nil and debounce == true) then
debounce = false
h.JumpPower = 50 //Just change this value//
wait(1)
debounce = true
end
end