Say that i want to make an altitude for a rocket game. But when I put the position of the rocket, it's a number value (Meaning its not a whole number, it's decimal. Because position property is decimal). So how can I solve this problem? Any ways?
local p = game.Players.LocalPlayer local n = p.Name.. "'s Folder" while wait() do local f = workspace:FindFirstChild(n) local part = f.Rocket.Part script.Parent.Parent.TextLabel.Text = "Altitude: ".. part.Position.Y end
Really, all numbers in Lua are floats. That means you can't "convert" a decimal number to an integer. Sometimes precision errors occur in floats, causing them to add tiny amounts to the actual number. The best way to manage this is by rounding it down with math.floor
.
local p = game.Players.LocalPlayer local n = p.Name.. "'s Folder" while wait() do local f = workspace:FindFirstChild(n) local part = f.Rocket.Part script.Parent.Parent.TextLabel.Text = "Altitude: ".. tostring(math.floor(part.Position.Y)) end
You can use the new function math.round
to quickly round a number:
math.round(part.Position.Y) -- good for visual display