Script prints the same value, even though value is changed

I have a script that is supposed to print the JumpHeight of the player. It was working until about an hour ago. I never changed anything to the script, yet when I change the JumpHeight of the player, it still prints the original value.

script:


local Player = game.Players.LocalPlayer
local humanoid = Player.Character:WaitForChild("Humanoid")
local JumpHeight = humanoid.JumpHeight

while wait() do
       print(JumpHeight)
end

For one thing, you shouldn’t be using while loops often. Second, I’m not sure if this will work but instead of making a local for the jump height, instead print(humanoid.JumpHeight).

JumpHeight is already a variable inside of the Humanoid, you dont need to set it inside of the script

Yes I have tested you solution, it works less

When you do a specific value as a variable, it won’t update automatically. This is useful in some cases: example storing the old transparency of a door, so you can set it back later.

1 Like

Yes, but I need to refrence it in multiple scripts which makes it easier just to use the preset variable in the humanoid

OH I see now you are referencing jumpHeight. Sorry. Well your script still only refernces the original value just set it every loop

1 Like

Well, maybe you can update the old value in the loop.

Example:

local Player = game.Players.LocalPlayer
local humanoid = Player.Character:WaitForChild("Humanoid") 
local JumpHeight = humanoid.JumpHeight 
while wait() do
JumpHeight = humanoid.JumpHeight
 print(JumpHeight) 
end
1 Like

Yes it works! Thank you so much!

1 Like

EmperorCraft has found the solution. Thank you for you time Max, have a good day!

I recommended wrapping it in a spawn function that returns if character is nil btw.

Also, you shouldn’t use a while loop as it will destroy performance.

Not really…

I have a lot of games that have while loops and run finw on my mobile and pc

Although loads can but that doesnt happen often

Yeah, I only have it in this script.

1 Like

True, but it’s really inefficient if used often and in a short period of time.

1 Like

True but setting this valie in a loop is fine as the script in it is only 1 line and isnt editing parts

1 Like