Gravity not changing on the client

Lately, I’ve made myself a gravity tool, which changed your gravity when equipping it, and then changes it back when unequipping.

My issue is that if a player dies/respawns with the tool equipped, they will keep their gravity after they respawn, which is slightly annoying.

What would be the best solution to patch this?
I’ve been trying to check when the script’s (and other objects’) parent is changed, but it won’t fire as the tool is destroyed before the script gets to run.

Most tools usually changes the properties of the humanoid, which would reset when the player respawns. I was actually thinking about setting the gravity on the server once someone respawned, but that would be even worse because if someone else in the server is also having the tool equipped, their gravity would change as well.

Can’t you use the Died event on the character’s Humanoid so when they die, their gravity gets reverted to normal?

I would try something like this:

local player = game:GetService("Players").LocalPlayer;
local character = player.Character; if not character then return end;
local humanoid = character:WaitForChild("Humanoid");

humanoid.Died:Connect(function()
       workspace.Gravity = 196.2 -- Set it back to normal gravity
end);

What’s up with the second line? Shouldn’t it be this?

local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

humanoid.Died:Connect(function()
    workspace.Gravity = 196.2 -- Set it back to normal gravity
end)

Sorry about that, I was thinking that would be better, since if they equipped it when they died, it wouldn’t set it back to normal.

It’s funny you mention player.CharacterAdded:Wait(), because that was the problem in the first place.

I simply check if the character exists instead of waiting for it now, which seemed to fix the issue.
Unequipped is fired if the tool’s parent is changed or destroyed.

The fix was truly a funny one, anyways - I appreciate the comments.

1 Like

Wow haha, can’t believe I accidentally mentioned the cause of the issue! Least it was eventually found out! If you have anymore issues don’t be afraid to make another post!

1 Like