Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is there a way to know if a character spawned into the game?

Something that tells me if a character spawned after death? I tried this but it doesnt seem to be working?

game.Players.PlayerAdded:connect(function(ply)
ply.CharacterAdded:connect(function(char)
print("works") --It doesnt print at all 
end)
end)

4 comments

0

Please read my bio, otherwise I will not answer your question.

0

this should work in a serverscript in serverscriptservice

0

Perhaps, you could detect when the player died. And then, try searching in the Workspace the character's name

0

Creeper hunter, thank you that worked for me!

1 answer

✓ Accepted answer

The first thing you should do is getting the player's name. Here is a simple way to:

local PlayerName = "?"

game.Players.PlayerAdded:Connect(function(player)
	PlayerName = player.Name
end)

...and then, you need to store the character's health...

-- Change the previous script to this:
local PlayerName = "?"
local PlayerHumanoid = "?"

game.Players.PlayerAdded:Connect(function(player)
	PlayerName = player.Name
	PlayerHumanoid = player:FindFirstChild("Humanoid")
end)

PlayerHumanoid = PlayerHumanoid.Health

..now, you will want to detect whenever the player dies? right?

-- Change the previous script to this:
local PlayerName = "?"
local PlayerHumanoid = "?"

game.Players.PlayerAdded:Connect(function(player)
	PlayerName = player.Name
	PlayerHumanoid = player:FindFirstChild("Humanoid")
end)

PlayerHumanoid = PlayerHumanoid.Health

if PlayerHumanoid == 0 then
	print("Player Died!")
end

..lastly, lets go to the point of what you ask!

-- Change the previous script to this:
local PlayerName = "?"
local PlayerHumanoid = "?"

game.Players.PlayerAdded:Connect(function(player)
	PlayerName = player.Name
	PlayerHumanoid = player:FindFirstChild("Humanoid")
end)

PlayerHumanoid = PlayerHumanoid.Health

if PlayerHumanoid == 0 then
	print("Player Died!")
	wait(5) -- This is the normal delay between every character's death
	game.Workspace:WaitForChild(PlayerName, 1)
	print("Player has respawned!")
end

Hope this helps! Tell me if it's wrong... :P

1 comment

0

Lastly, what if you use :LoadCharacter?

This discussion is preserved as it was. New answers, comments, and votes are closed.