String does not update

Hey, I’m trying to make a script that constantly updates the text in a GUI with the player’s velocity, but it doesn’t seem to work.

image

Just to be clear, there are no errors in the output. The number just stays stuck at 0

The code I'm trying to use for this
local player = game:GetService("Players").LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local text = script.Parent

local velocity = (character.HumanoidRootPart.Velocity * Vector3.new(1,0,1)).Magnitude

function roundNumber(num, numDecimalPlaces)
    return string.format("%." .. (numDecimalPlaces or 0) .. "f", num)
end

game:GetService("RunService").RenderStepped:Connect(function()
    text.Text = roundNumber(velocity, 1)
end)

Help is appreciated, thank you in advance.

It’s not that the text isn’t updating, because it is. If you print velocity, you’ll find that velocity isn’t updating. Move the local velocity = line to the inside of the RenderStepped function.

4 Likes

it’s the third time I overlook something entirely and it ended up being the solution to the whole issue :man_facepalming:
I appreciate the help dude

1 Like