PlayerAdded not firing

I can’t really use player.characteradded when players.playeradded isn’t working in studio correctly, I’m trying to connect it to the function that fires after the player has been added.

I’m not too sure what you mean, but I know that this is a result of you not using or understanding PlayerAdded or what I’m saying, not that PlayerAdded doesn’t work in Studio - the latter part is why the line to iterate over players already in the server exists.

It would probably help to show you exactly what’s the issue. May you supply a code sample and explain what the problem is?

Apologies for the small bit of hostility on the first response, but this is a raw idea of what I’m trying to do:

local function PlayerAdded(Player)
	Player.CharacterAdded:Connect(function()
		print("Test")
	end)
end

for _, player in ipairs(Players:GetPlayers()) do
	PlayerAdded(player)
end

However “test” never prints out and I can’t figure out a way to make it work unfortunately.
I know It looks a bit dumb but I’ve never really tried working with a system like this.

Nevermind, figured it out. Thanks for being ready to help though!

If you figure it out, then it’s good to reply with the conclusion you arrived at so others can reference your answer rather than just ending it off at “I figured it out”. In any case, for anyone else, it’s as I said before - this is a problem with the code, not PlayerAdded.

Characters similarly need to be checked for existing or new ones, especially in a deferred environment (and in turn, almost anything that has a matching GetX/property for an Added event):

local function onPlayerAdded(player)
    local function onCharacterAdded(character)
    end

    player.CharacterAdded:Connect(onCharacterAdded)
    if player.Character then
        onCharacterAdded(player.Character)
    end
end

Players.PlayerAdded:Connect(onPlayerAdded)
for _, player in Players:GetPlayers() do
    onPlayerAdded(player)
end
1 Like