For whatever reason it gives me negative numbers when I fall or doesn’t detected that I was falling at all. If anybody knows how to fix this please let me know how
Thanks in advance to all who reply
Here’s my code:
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local Velocity = 0
local Humanoid = character:WaitForChild("Humanoid")
local Root = character:WaitForChild("HumanoidRootPart")
local states = {
[Enum.HumanoidStateType.Freefall] = function()
Velocity = math.abs(Root.Position.Y)
end,
[Enum.HumanoidStateType.Landed] = function()
Velocity = math.abs(Velocity - math.abs(Root.Position.Y))
if math.ceil(Velocity) >= 20 then
Humanoid:TakeDamage(Velocity)
Velocity = 0
end
end
}
Humanoid.StateChanged:Connect(function(_, newState)
local func = states[newState]
if func then
func()
end
end)
end)
end)