Hello Everyone!
I am currently making a speed counter prototype, but I need it to round to the nearest number, except without having it go to the next number. For example, I want to make 15.92 into just 15, not 16 or 15.92.
If anybody can help please do. (Also this isn’t the official UI design, just a placeholder)
You’ll be wanting to use math.round(number)
1 Like
Alright, thanks! Let me try it.
I just need to know where in the script, because I do not have any experience in the math
section in roblox.
Heres the script:
local player = game.Players.LocalPlayer
local char = player.Character
local humanoidrootpart = char:WaitForChild("HumanoidRootPart")
while true do
wait()
if humanoidrootpart == nil then return end
script.Parent.ScreenGui.TextLabel.Text = humanoidrootpart.Velocity.Magnitude.." studs/s"
end
Edit: Wait a second, I think I found it out.
You want to round this number here.
I don’t think it’s working. Maybe I am doing it the wrong way? Here’s the updated script:
local player = game.Players.LocalPlayer
local char = player.Character
local humanoidrootpart = char:WaitForChild("HumanoidRootPart")
math.round(humanoidrootpart.Velocity.Magnitude)
while true do
wait()
if humanoidrootpart == nil then return end
script.Parent.ScreenGui.TextLabel.Text = humanoidrootpart.Velocity.Magnitude.." studs/s"
end
math.round actually doesn’t change the original result, it creates a new one which you can either save to a variable or use in-line:
script.Parent.ScreenGui.TextLabel.Text = math.round(humanoidrootpart.Velocity.Magnitude).." studs/s"
Alright I’ll try it out thanks!
Thank you so much, it worked. .
1 Like