Humanoid Reseting When Died

Hello, I’m trying to make a script that allows player to enable/disable low gravity in a gui, but I’m currently having problems with it because once the player died their JumpPower goes back to normal.

This is a local script. Here’s what is inside:

local LocalPlayer = game:GetService("Players").LocalPlayer
local char = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()

script.Parent.MouseButton1Click:Connect(function()
	
	if script.Parent.Text == "Low Gravity: Off" then
		
		script.Parent.Text = "Low Gravity: On"
		
		char.Humanoid.JumpPower = 75
		
		
		
	elseif script.Parent.Text == "Low Gravity: On" then
		
		script.Parent.Text = "Low Gravity: Off"
		
		
		char.Humanoid.JumpPower = 50
		
		
		
	end
	
	
	
	
	
end)

My question is, how would I make it so their jumppower stays the same after they die? Any responses are helpful, thanks.

You can use Player.CharacterAdded. This function will run whenever a new character is added into the game. When a player dies, their old character gets destroyed and a new one spawns. Once you have fired the character added event, change the jumppower there. This will update the jumppower when the character spawns, as all the values reset when a character dies.

Try:

local LocalPlayer = game:GetService("Players").LocalPlayer

LocalPlayer.CharacterAdded:Connect(function(Character)
     script.Parent.MouseButton1Click:Connect(function()
	
	if script.Parent.Text == "Low Gravity: Off" then
		
		script.Parent.Text = "Low Gravity: On"
		
		char.Humanoid.JumpPower = 75

	elseif script.Parent.Text == "Low Gravity: On" then
		
		script.Parent.Text = "Low Gravity: Off"
		
		char.Humanoid.JumpPower = 50
	end
end)

This should run the code and set the jumppower every time a character respawns.

1 Like

Using the CharacterAdded function before the MouseButton1Click broke the script. Should I use a local function?

Oh my bad. I forgot to swap the char and character. This should work.

local LocalPlayer = game.Players.LocalPlayer

LocalPlayer.CharacterAdded:Connect(function(Character)

     script.Parent.MouseButton1Click:Connect(function()

	if script.Parent.Text == "Low Gravity: Off" then
		
		script.Parent.Text = "Low Gravity: On"
		
		Character:WaitForChild("Humanoid").JumpPower = 75

	elseif script.Parent.Text == "Low Gravity: On" then
		
		script.Parent.Text = "Low Gravity: Off"
		
		Character:WaitForChild("Humanoid").JumpPower = 50
	end
end)
end)

Weird, it’s still breaking. The text and the JumpPower aren’t changing at all.

Try printing something after the character has been added and after the button has been clicked. Is it printing?

Also are you getting any errors in the output?

No errors in the output, and it didn’t print anything at all.

You can save the player’s gravity with an IntValue inserted under the ReplicatedStorage and when they die you can replace their gravity with the IntValue.

I tried doing this:

game.Players.PlayerAdded:Connect(function(plr)
	
	
	local Jump = plr:WaitForChild("Jump")
	
	
	
	plr.CharacterAdded:Connect(function(char)
		
		
		char.Humanoid.JumpPower =  Jump.Value
		
		
	end)
	
	
	
end)

But the player’s jumppower doesn’t change.

This changes the jump power locally so it is not registered by the server.

You can change it to when the player clicks the button, it will fire a remote event which you can then use to either change a variable created within the server script on an IntValue to change the JumpPower whenever the Character is added.

1 Like