Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to compare a previous value to a current value?

Asked by 2 years ago

I want to determine how far the player is from the ground and detect their peak maxheight. I am trying to do this by detecting the rootpart's position and subtracting it by a part on the grounds position. I think the problem is that the two values are not comparing correctly, any help?

distanceBool.Changed:Connect(function()
    if distanceBool.Value then
        while task.wait() do
            local groundPart = game.Workspace.ground
            local currentHeight = (character.HumanoidRootPart.Position.Y - groundPart.Position.Y)
            local maxHeight = 0
            if currentHeight > maxHeight then
                maxHeight = currentHeight
            end     
            if not distanceBool.Value then
                break
            end
            print(maxHeight,"maxHeight")
        end
    end
end)
1
On line 6 you are setting maxHeight to 0 before you do your check every time. Move it outside of your function so it saves from line 8. climethestair 1663 — 2y

Answer this question