user12259027
user12259027

Reputation:

How to round towards zero in lua

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

Answers (1)

Related Questions