(This is my first post, so sorry if I have done something wrong)
I need to have a script able to work out the distance that a player has fallen, say if they fell off a platform that was 5 studs off the baseplate, then the distance fallen would be 5.
This is the code I have so far
while true do wait(0.2)
height = chr.HumanoidRootPart.Position.y
if oldheight ~= nil then
difference = oldheight - height
if difference ~= nil and difference > 0 then
difference = oldheight - height
else
difference = nil
end
end
print(difference)
oldheight = height
end
You can get the height they were when they started falling, then when they landed on the ground, you would get the difference between the height they started falling and the height they are on now on the ground. This can be done using the StateChanged event of the Humanoid.
For example:
local stateType = Enum.HumanoidStateType
local falling_height
local dist
Humanoid.StateChanged:Connect(function(old, new)
if new == stateType.Freefall then
falling_height = HumanoidRootPart.Position.y
elseif old == statetype.Freefall and new == statetype.Landed then
dist = falling_height - HumanoidRootPart.Position.y
end
end)
Edit: stateType.Freefalling was changed to stateType.Freefall