Hello! i this post i want to know what are the differentes of PlayerAdded and CharacterAdded?
The PlayerAdded event fires when a player enters the game. This is used to fire an event when a player joins a game, such as loading the player’s saved
GlobalDataStore
data.
The CharacterAdded event fires when a player’s character spawns (or respawns). This event fires soon after setting
Player.Character
to a non-nil value or callingPlayer:LoadCharacter
. Note, CharacterAdded fires when the Character is assigned to thePlayer
, which is before the Character is parented to theWorkspace
.
And can they be used in a localscript or does the “getservice” only work in a server script?
:GetService
works in all scripts and yes, events specified above works in localscripts too.
game:GetService(“Players”) is basically the same as game.Players. GetService is mainly important for services that aren’t in the explorer, like game:GetService(“UserInputService”).
Thanks you guys!
Am I using well my code to call when someoner respawn?
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
print(player.Name .. " joined the game!")
player.CharacterAdded:Connect(function(character)
print("Spawn")
end)
end)
Players.PlayerRemoving:Connect(function(player)
print(player.Name .. " left the game!")
end)
Yes, that script will print “Spawn” when someone spawns in. I suggest making a new thread for each new question. Makes it easier for people to see and respond.
Thanks a lot! I was not sure since the ide did not show me suggestions, how could i active it?