Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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)

0
Please read my bio, otherwise I will not answer your question. hiimgoodpack 2009 — 6y
0
this should work in a serverscript in serverscriptservice creeperhunter76 554 — 6y
0
Perhaps, you could detect when the player died. And then, try searching in the Workspace the character's name Aquaventurer 26 — 6y
0
Creeper hunter, thank you that worked for me! shootthegame 14 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

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

0
Lastly, what if you use :LoadCharacter? hiimgoodpack 2009 — 6y
Ad

Answer this question