I’m trying to implement fall damage in my game, and I’m using Enum.HumanoidStateType.Landed to check when the player has landed. The problem is that half of the time the script doesnt detect that the player landed. Here is an example of what is happening:
here is the script not working:
https://gyazo.com/0a90d5dcaf643886eb4fd643f1ea0daa
here is the script working:
https://gyazo.com/f5dc8c9e9464eb7dfe3ffabbf6914ea1
and here is the script I used:
local Ragdoll = require(game.ReplicatedStorage.Modules.Ragdoll)
local players = game.Players
players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(plr)
local hum = plr.Humanoid
local HRP = plr.HumanoidRootPart
local falling = false
local fallcount = 0
local startpos
hum.StateChanged:Connect(function(oldstate,newstate)
if newstate == Enum.HumanoidStateType.Freefall then
startpos = HRP.Position.Y
hum.JumpPower = 0
elseif newstate == Enum.HumanoidStateType.Landed then
local endpos = HRP.Position.Y
if (startpos - endpos) >= 15 then
hum.Health = hum.Health - ((startpos-endpos)/2)
Ragdoll(player.Character, true)
wait(3)
Ragdoll(player.Character, false)
end
wait(1)
hum.JumpPower = 50
end
end)
end)
end)
Thanks in advance for any help!