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

Any reason why this code doesn't fire each time the character spawns?

Question is in the title. I'm having trouble getting this code to fire each time the character spawns.

local remoteEvent = game.ReplicatedStorage.RemoteEvent

local function onCharacterAdded(character) print("1")
	remoteEvent:FireClient(character)
end
 
Players.PlayerAdded:Connect(onCharacterAdded)

I feel like I'm most likely making a stupid mistake, but any help would be appreciated.

1 comment

0

Whoops! Thanks for the comment, I had an error in my answer I provided. It's been updated to meet the criteria you provided.

1 answer

The error is that you're using the function when the Player is joining the game, not the Character spawning.

For what you're asking, we will be using the CharacterAdded event with the player.

Here's the revised code:

local remoteEvent = game.ReplicatedStorage.RemoteEvent

game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(character)
		remoteEvent:FireClient(character)
	end)
end)

This should (in theory) work out for you, if you have any questions or concerns, feel free to post such in the comments and we can work it out!

1 comment

0

Thanks for the help, however, your revised code still only runs once, and wont fire a second time once the character has respawned.

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