Doing something after a player dies/resets

I want to create an afk system where if they die/reset, they automatically get tp’ed back to the afk house. I already have a “system” written, but when I test it, it fails to tp me

This is the system that I have so far

function checkUser(plrName)
	local plrChar = game.Players:FindFirstChild(plrName).Character
	local didDie = false
	if plrChar.Humanoid.Health == 0 then
		didDie = true
	end
	if didDie == true then
		if not plrChar.Humanoid.Health == 0 then
			plrChar:MoveTo(game.Workspace["AFK Place"].Spawn.Position)
		end
	end
end

There’s no errors in the console, so I don’t have anything to go on

2 Likes

do this:

plrChar.Humanoid.Died:Connect(function()
    --code
end)

You can use the Humanoid.Died event to detect when a player dies, and the Player.CharacterAdded event to tell when a character respawns.

Player.CharacterAdded:Connect(function()
   --character was loaded
end)

Humanoid.Died:Connect(function()
    --character has died
end)
2 Likes

Oh, I didn’t know that .Died was a thing

I tried doing that, still didn’t work, now it’s the following code

plr.CharacterAdded:Connect(function()
		if table.find(afkedPlayers, plr.Name) then
			plr.Character:MoveTo(game.Workspace["AFK Place"].Spawn.Position)
			plr.Character.Humanoid.MaxHealth = 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368
			plr.Character.Humanoid.Health = plr.Character.Humanoid.MaxHealth
		end
	end)

Maybe the if statement isn’t registering true? Remove it temporarily and see if it works. Also, where is the script located?

That code is located in the PlayerAdded event and table.find() won’t return true, but it’ll return a number, which it does. When I removed the if statement, it still didn’t work

I meant the location of the script object itself. What is its parent? If you place print at the start of the script, does it appear in the output?

ServerScriptStorage is where the script is and it does output something when I do print()

Uhh hello? It’s been a day since I’ve answered, just making sure you got the answer to your question @ExcessEnergy