When I get Killed my script does not work anymore

I made a fall damage script and it works but when I die and respawn the script does not damage me anymore.

script:

local min = 9
local max = 49
local w
local fall
game.Players.PlayerAdded:Connect(function(player)
	wait(2)
	local char = player.Character
	local hum = char.Humanoid
	local humrootpart = char.HumanoidRootPart
	print(humrootpart.Position.Y)
	hum.StateChanged:Connect(function(old, new)
		if new == Enum.HumanoidStateType.Freefall then
			w = humrootpart.Position.Y
		elseif (new == Enum.HumanoidStateType.Landed and old == Enum.HumanoidStateType.Freefall) or (new == Enum.HumanoidStateType.Running and old == Enum.HumanoidStateType.Freefall) then
			fall = w - humrootpart.Position.Y
			print(fall)
			if fall >= max then
				hum.Health = 0
			elseif fall >= min then
				hum.Health -= math.floor(fall)
			end
		end
	end)
end)

put a characterAdded event inside of the playerAdded event

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
--do stuff
end)
end)

yeah, cos he just run the code once player joins the game

Thank you I added that and now it works

1 Like