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.
COMMUNITY QUESTION
Is there a script that could measure how far I fall?
1 answer
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)
This discussion is preserved as it was. New answers, comments, and votes are closed.
