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

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

Asked by 7 years ago
Edited 7 years ago

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.

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. TrippyV 314 — 7y

1 answer

Log in to vote
0
Answered by
TrippyV 314 Donator Moderation Voter
7 years ago
Edited 7 years ago

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!

0
Thanks for the help, however, your revised code still only runs once, and wont fire a second time once the character has respawned. SevenRubyRobes 6 — 7y
Ad

Answer this question