Script not changing Humanoid JumpPower after death

I have a script that changes the Humanoid’s JumpPower to match an intvalue every second.
However I just recently noticed that it stops changing the jumppower after the player dies or resets.
I put a print() test to find out if the script was still running and it is.

game.Players.PlayerAdded:Connect(function(plr)
	local char = plr.CharacterAdded:Wait()
	local humanoid = char:WaitForChild("Humanoid")
	local JpMulti = plr.JpMulti.Value
	while true do
		wait(1)
		plr.leaderstats.JumpP.Value = plr.leaderstats.JumpP.Value + JpMulti
		if plr.jumpSet.Value == false then
			humanoid.JumpPower = plr.leaderstats.JumpP.Value
			print("test")
		end
		if plr.leaderstats.JumpP.Value >= 160 then
			humanoid.WalkSpeed = plr.leaderstats.JumpP.Value/10
		end
	end
end)

Is it happening because the script isn’t grabbing the new character? and if so how would I make it grab the new character?

You could use something like this instead:

game.Players.PlayerAdded:Connect(function(plr)
	local JpMulti = plr.JpMulti.Value
	while true do
		wait(1)
		if plr.Character then
			plr.leaderstats.JumpP.Value = plr.leaderstats.JumpP.Value + JpMulti
			if plr.jumpSet.Value == false then
				plr.Character.Humanoid.JumpPower = plr.leaderstats.JumpP.Value
				print("test")
			end
			if plr.leaderstats.JumpP.Value >= 160 then
				plr.Character.Humanoid.WalkSpeed = plr.leaderstats.JumpP.Value/10
			end
		end
	end
end)

This is because the character and humanoid you are using is their first character and humanoid. Alternatively, you could update the character and humanoid after every respawn.

You can also replace this:

while true do
    wait(1)

With this:

while wait(1) do
1 Like

Thank you! This solved it!
I thought it was because it was only grabbing the first character, I couldn’t think of a simple way to have it grab each character. :grinning: