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

Is there a script that could measure how far I fall?

Asked by
parkgu -7
6 years ago

I'm making a game and I need to know is there a script that measures how far I fall and then hold the longest I fell as a record? Like my highest.

1 answer

Log in to vote
0
Answered by 6 years ago

This script will have separate records for each player. It records two types of fall distances (since I'm not sure which one you wanted)

Vertical: The vertical distance between the jump point and the landing point. Absolute: The full distance between the jump point and the landing point.

If you were to be walking forward during the fall, the "Vertical" distance won't be affected, but the "Absolute" distance will be higher.

Put this in a Script in ServerScriptService. Works with FilteringEnabled.

game.Players.PlayerAdded:Connect(function(player)
    local recordFallAbsolute
    local recordFallVertical
    player.CharacterAdded:Connect(function(character)
        local humanoid = character:WaitForChild("Humanoid")
        local root = character:WaitForChild("HumanoidRootPart")
        local fallStartPos
        local fallEndPos
        humanoid.StateChanged:Connect(function(oldState, newState)
            if newState == Enum.HumanoidStateType.Freefall then
                fallStartPos = root.Position
            elseif oldState == Enum.HumanoidStateType.Freefall then
                fallEndPos = root.Position
                local fallAbsolute = (fallStartPos - fallEndPos).magnitude
                local fallVertical = fallStartPos.Y - fallEndPos.Y
                if fallVertical < 0 then
                    -- don't count jumping up as a "fall"
                    return
                end
                if not recordFallAbsolute
                or fallAbsolute > recordFallAbsolute then
                    recordFallAbsolute = fallAbsolute
                    print(player.Name..
                        " set their new record fall distance (absolute):",
                        recordFallAbsolute)
                end
                if not recordFallVertical
                or fallVertical > recordFallVertical then
                    recordFallVertical = fallVertical
                    print(player.Name..
                        " set their new record fall distance (vertical):",
                        recordFallVertical)
                end
            end
        end)
    end)
end)
Ad

Answer this question