Soukza
(HBlake001)
January 6, 2022, 1:39am
#1
I made a script that displays the orientation of a part inside of a car. it works but it shows the EXACT number. I want to round that number to the nearest whole number. I have tried math.round() but it doesn’t work.
local car = script.Parent.Parent.Parent.Parent.Car.Value
while true do
wait(0.5)
script.Parent.Text = (car.Body.ROLL.Orientation.X)
end
Please look for the answer in pre-existing posts before making a new one
Soukza
(HBlake001)
January 6, 2022, 1:42am
#3
I have, but I could not find any solutions.
The first thing that popped up when I googled “roblox round to nearest whole number” was this. for the actual code, use
local function round(n)
return math.floor(n + 0.5)
end
Ocipa
(Ocipa)
January 6, 2022, 1:49am
#5
what do you mean it doesn’t work, what did you try and what was the result
print(math.round(0.999)) -- prints 1
print(math.round(0.4)) -- prints 0
print(math.round(5.5)) -- prints 6
note: you have 3 common options
math.floor(num) -- rounds down
math.ceil(num) --rounds up
math.round(num) --rounds to the nearest
and you can use @XxFishShadowxX method, but I would just suggest use round
2 Likes
Soukza
(HBlake001)
January 6, 2022, 2:35am
#7
when i use math.round() i get this error message.
Ocipa
(Ocipa)
January 6, 2022, 2:38am
#8
what is the exact code, copy and paste the line with math.round.
Soukza
(HBlake001)
January 6, 2022, 2:39am
#9
local car = script.Parent.Parent.Parent.Parent.Car.Value
while true do
wait(0.5)
script.Parent.Text = (car.Body.ROLL.Orientation.X)
end
Ocipa
(Ocipa)
January 6, 2022, 2:41am
#10
where is math.round, I meant the code that caused the error, but here, what you want is this
script.Parent.Text = math.round(car.Body.ROLL.Orientation.X)
Soukza
(HBlake001)
January 6, 2022, 2:41am
#11
script.Parent.Text = math.round(car.Body.ROLL.Orientation.X.math.round())
Ocipa
(Ocipa)
January 6, 2022, 2:42am
#12
now that I know what you typed, this makes it easier, thank you, yes just remove the math.round at the end there, you only need the first one
1 Like
gooey333
(StandardSatire)
January 6, 2022, 2:42am
#13
script.Parent.Text = math.round(car.Body.ROLL.Orientation.X)
1 Like