Hi developers, so I’m trying to create a fall damage script, everything works, but after I die the script won’t work anymore, does anybody know how to fix it?
It’s a LocalScript located inside the StarterPlayerScripts:
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local CanStart = true
local LastYPostition = nil
local FallDistance = nil
while wait() do
if CanStart then
CanStart = false
repeat wait() until Humanoid.FloorMaterial == Enum.Material.Air
wait(0.1)
LastYPostition = Character.PrimaryPart.Position.Y
end
repeat wait() until Humanoid.FloorMaterial ~= Enum.Material.Air
if LastYPostition ~= nil then
FallDistance = (LastYPostition - Character.PrimaryPart.Position.Y)
end
if FallDistance ~= nil then
if FallDistance <= math.huge and FallDistance >= 15 then
Humanoid:TakeDamage(FallDistance)
end
end
CanStart = true
end
print("ended")
Edit: And It’s not printing “ended”
