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
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
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.