currently im making a custom fall damage script that ragdolls the player if they fall for more that 0.7s but the FreeFall state only works if the player jumps so if the player walks off a building no damage or ragdoll is given, how do i fix this? the script below is a local script under sps.
local player = game.Players.LocalPlayer
local deadly = false
local fallingEvent = game:GetService("ReplicatedStorage"):WaitForChild("FallingEvent")
local fallingStartTime = nil
local function onCharacterAdded()
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
humanoid.StateChanged:Connect(function(oldState, newState)
if newState == Enum.HumanoidStateType.Freefall then
fallingStartTime = tick()
elseif oldState == Enum.HumanoidStateType.Freefall then
local fallingDuration = tick() - fallingStartTime
if fallingDuration > 0.7 then
fallingEvent:FireServer()
end
fallingStartTime = nil
end
end)
print("Player respawned")
fallingStartTime = nil
print("reset fallingtime")
print(fallingStartTime)
end
player.CharacterAdded:Connect(onCharacterAdded)
``