Saving JumpPower

local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		while wait(1) do
			char.Humanoid.JumpPower = char.Humanoid.JumpPower + 1
			
	end
		end)
	end)

I have this script but everytime a player dies the jumpPower is resetting to 50 how can i make it not reset?

The function “restarts” everytime the player’s character dies and respawns.
You would need to create a value and place it outside of the character. Then, increment this value every second and have the character listen to this value change.

1: make a separate variable that will indicate the player’s jump power
2: check when the player respawns and set it to the value of the separate variable

i already tried that but it doesn’t work

The jump power goes back to normal, but the function doesn’t restart.

oh maybe that could work because i did was check when a player dies

but how can i check when a player respawns?

You don’t have to, I have a better idea, just first make a variable that will be the players current jump power, then you will just add 1 to it every second, and then the line that changes the jump power, just set it to the value, it will still work because you added 1 to the value, yet it will save.

can you show me a sample code to make it clearer?

Hence the “quotation marks”.
The function is inside a CharacterAdded event, so it will start a new count every time.
I even think the more characters respawn, the more functions are being connected and not disconnected, delivering undesired behavior.

You have everything set up the way it should be. The only thing you’re missing is a variable that is saved after the player dies.

You can tell when the player respawns through your CharacterAdded function. Make a value that is stored within the player (or a variable if you want to do this through a local script) that you change every second.

here’s a psuedoexample of something that you might make in a localscript;

local jumppower = 50
game.Players.LocalPlayer.CharacterAdded:connect(function(c)
    while wait(1) do
        c.Humanoid.JumpPower = jumppower
        jumppower = jumppower + 1
    end
end)

robloxapp-20200819-1040168.wmv (1.4 MB)

here is what happened if i use another vairable

local jumppower = 50 — starting jumppower

— your loop:
while wait(1) do
— then just change the players jump power to “jumppower”!

jumppower = jumppower + 1

end

Yes, an having a whole while loop in that function just creates so much memory loss.

1 Like

I would also recommend you think about your problem before posting on devforum.