How to check if a character has died after wait has ended

This may be a simple solution for some of you guys but I can’t seem to figure it out. All I want to check is if the player has died during the time frame of the wait.

What I could do is character.Humanoid.Died before the wait and set a variable that the char has died but I thought there used to be a simpler solution like the one below.

local function PlayerPressedE(Player)
	local Character = Player.Character
	wait(20)
	if Character then
		--do stuff
	else
		print("Player died during the wait")
	end
end

Just hold a reference to the player’s humanoid and check if its health is 0, should do the job. Unless you want to cancel the wait?

It works fine now thanks. I just thought the old character gets deleted when they die along with reference.

Destroys don’t actually release references (and thus, memory), only remove/lock the object along with disconnecting events. Not even sure if characters are deleted, at a time they weren’t.

Yeah makes sense now and also here is the new code if anyone wants it

local function PlayerPressedE(Player)
	local Character = Player.Character
	wait(20)
	if Character.Humanoid.Health ~= 0 then
		--do stuff
	else
		print("Player died during the wait")
	end
end

if Humanoid:GetState() ~= Enum.HumanoidStateType.Dead then
	--do code
end

This would be the more accurate way of achieving this, as the “Health” property is a float.
https://developer.roblox.com/en-us/api-reference/function/Humanoid/GetState