I am trying to script a system that will create a StringValue for each player that joins the game into a model in workspace to create a “list”. But when I test my game in studio, using a local server with 3-6 players, the PlayerAdded event appears to only fire for the first two players that join.
I’ve tried looking for a reason that might be causing this but if I had to guess it might be because I am using studio to test my game? I’m just worried about this happening in my game if a bunch of people join at once. Is this just a studio thing or am I misusing the PlayerAdded event? It seems to work fine for more than 2 people when playing through the game itself, outside of studio.
Here’s my code:
Players.PlayerAdded:Connect(function(player)
--Set up the list
local pool = game.Workspace.List
local person = Instance.new("StringValue")
person.Parent = pool
person.Name = player.Name
person.Value = player.Name
print("New person: "..person.Value)
print("# of kids in workspace: " ..#pool:GetChildren())
end)
This is all that I see in the testing server:
Any help is appreciated!
Some players load in faster than the event itself in studio, meaning you’d have to call the function for existing players as well. Example would be in this video : Roblox: Doing PlayerAdded Correctly - YouTube
1 Like
local function PlayerAdded()
local pool = game.Workspace.List
local person = Instance.new("StringValue")
person.Parent = pool
person.Name = player.Name
person.Value = player.Name
print("New person: "..person.Value)
print("# of kids in workspace: " ..#pool:GetChildren())
end
local GetPlayers = Players:GetPlayers()
for i = 1, #GetPlayers do
local Player = GetPlayers[i]
coroutine.resume(coroutine.create(function()
PlayerAdded(Player)
end))
end
This should make it run for players that load faster than others, like @ThunderFrost0001 said.
I’ve tried both of the above solutions but the same thing appears to be happening, where only the first two players get added to the list. I’ll keep the call to the function for existing players to prevent any other possible problems, but that doesn’t seem to have solved my overall issue. Maybe it’s just a studio thing?
Well I was actually able to diagnose this pretty quickly. It turns out I had a lot of scripts for datastore calls and they must have been overloading the server when all the players joined at once. Thanks for the suggestions though, it appears to just have been some poor scripting on my end.