Math.floor returns 2 when the number is 3.9626...?

I’ve made a stud height GUI that shows how high are you in studs from the Y axis of your PrimaryPart of your character. I use math.floor() to prevent decimals from appearing but in exchange, the script kind of malfunctions?

Here’s a GIF below to show the problem.
RobloxStudioBeta_If5Kl8c8Nz

On the left is me along with the GUI above and on the right is the output. The output prints out both the math.floor() number and the original number. They don’t match with the GUI.

I’m not sure if it’s my code making it look weird or math.floor() is having a field trip.

Here’s my code.

rs.RenderStepped:Connect(function()
	if char.Parent ~= nil and char and char.PrimaryPart then
		print(math.floor(char.PrimaryPart.Position.Y),char.PrimaryPart.Position.Y)
		script.Parent.Text = string.format('<stroke color="#323232" joins="miter" thickness="3" transparency="0"><font size="50">%s</font><br/><font size="25">studs</font></stroke>', math.floor(char.PrimaryPart.Position.Y))
	end
end)

I’ve also tried math.round() and math.ceil() but both returned the same result (4 and 3 this time.)

3 Likes

Try storing math.floor(char.PrimaryPart.Position.Y) in a variable, and then use that in the print() and string.format(). If it still happens, there’s probably something wrong with the GUI.

Also, what would happen if you jump?

1 Like

I did your variable method, same result.

Jumping does change the number, I just mean when you walk above parts that is the issue.

1 Like

Oh wait-

RenderStepped was the issue. Switched to Heartbeat and that fixed it!

I really need to check the documentation of RunService…

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.