How to make textlabel update with the player's jump power

i want my textlabel to show “jump power: the jump power” but i have no idea how to make it update everytime the jump power changes because the player gets +1 jump power every second so i just put a while true loop hoping it would work. it didn’t. anyone know how i can do this?
also sometimes it show like 50.93892429482894 or something as the jump power but i want it to stay as like one whole number and not a bunch of decimals or whatever

local text = script.Parent

local jumpPower = game.Players.LocalPlayer.Character:WaitForChild("Humanoid").JumpPower

while true do
	wait(1)
	text.Text = "jump power: ".. jumpPower
end

btw i have another script that increases the jump power every second so that’s not a problem or anything

Just move the source of the value into the while loop.

while true do
	wait(1)
	local jumpPower = game.Players.LocalPlayer.Character:WaitForChild("Humanoid").JumpPower
	text.Text = "jump power: ".. jumpPower
end
1 Like

You can round the number with a bit of code:

1 Like

oh wow it actually works, thanks i didn’t think of that.

Rather than using an infinite loop, I’d recommend only updating it when the game detects that it has changed. This can be achieved with :GetPropertyChangedSignal().

Additionally, if the ScreenGui does not have ResetOnSpawn enabled, the infinite loop would break after the player’s Character respawns because the code would be referring to the old Character rather than the newly spawned one.

Lastly, you can use math.floor() on the final value so that it rounds down to the nearest whole number rather than remaining a decimal.

Example Revision

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

local TextLabel = script.Parent
local connection


local function characterRespawn(Character)
    if connection then
        connection:Disconnect()
        connection = nil
    end

    local Humanoid = Character:WaitForChild("Humanoid")

    connection = Humanoid:GetPropertyChangedSignal("JumpPower"):Connect(function()
        local roundedJumpPower = math.floor(Humanoid.JumpPower)
        TextLabel.Text = "Jump Power: "..tostring(roundedJumpPower)
    end)

end

if player.Character then
    characterRespawn(player.Character)
end

player.CharacterAdded:Connect(characterRespawn)

I was about to say this, @GamerAlex323. Although his option works, while loops use more resources than an event like getpropertychangedsignal. So I recommend using an event like :GetPropertyChangedSignal.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.