Reputation:
I have to round a value towards zero to know when it has gotten 1 larger than before
I have tried rounding normally but it doesn't work as I wanted.
local ghostwalkspeed = 0
function onTouched(hit)
if hit.Parent:FindFirstChild("Humanoid") then
hit.Parent.Humanoid.WalkSpeed = hit.Parent.Humanoid.WalkSpeed + hit.Parent.Humanoid.WalkSpeed/100
--!!!!!!
-- In the if statement below I have to
-- round "hit.Parent.Humanoid.WalkSpeed" towards zero
--!!!!!!
if hit.Parent.Humanoid.WalkSpeed > ghostwalkspeed then
ghostwalkspeed = hit.Parent.Humanoid.WalkSpeed
end
end
end
script.Parent.Touched:connect(onTouched)
Ghostwalkspeed is 0, walkspeed is 1. The ghost variable should not change to walkspeed until walkspeed is 2, so it should round from 1.9 to 1.
Upvotes: 1
Views: 400
Reputation: 28950
math.floor(1.9)
or 1.9//1
will both evaluate to 1
.
Lua Reference Manual 3.4.1. Arrithmetic Operators
Lua Reference Manual 6.7 Mathematical Functions: math.floor
https://en.wikipedia.org/wiki/Floor_and_ceiling_functions
Please read manuals!
Upvotes: 0