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

How could I allow my server sided code to run on multiple joining players at once?

Here is a bit of a better explanation on my issue: I have created some sort of player list that lists everybody else, but the user on the UI, so I am player1, but I only want to see player2 on the list and vise versa. When I try to join in with the Studio test with 3 players and above it shows it perfectly fine to all other users, but the first one that has joined in.

If further information is needed I will try and provide you with it. Thanks in advance!

The code:

local PlayerExample = script:WaitForChild("PlayerExample")

game.Players.PlayerAdded:Connect(function(player)
	local PlayersFolder = player:WaitForChild("PlayerGui"):WaitForChild("StartMenu"):WaitForChild("PvP_Tab"):WaitForChild("Players")
	local AllPlayers = game.Players:GetChildren()
		for i,v in pairs(PlayersFolder:GetChildren()) do
			if not v:IsA("UIGridLayout") then
				v:Destroy()
			end
		end
	for i,k in pairs(AllPlayers) do
		if k.Name ~= player.Name then
				local newPlayerButton = PlayerExample:Clone()
				newPlayerButton.Name = k.Name
				newPlayerButton.PlayerName.Text = k.Name
				local UserId, ThumbType, ThumbSize =  k.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size100x100
				newPlayerButton.AvatarImage.Image = game.Players:GetUserThumbnailAsync(UserId, ThumbType, ThumbSize)
				newPlayerButton.Parent = PlayersFolder
		end
	end
end)

7 comments

0

What exactly problem with the first one? He can't see the list, or see himself?

0

My idea is that the player list shows you all other players, but you. Works fine with all other players, but nothing appears to player1

0

But are you sure, that player2 can see player3 in the list? Looks like your script only adding all existed players, so player1 cant see player2 AND player3, next player2 can't see player3. For example, player3 couldn't see player4+, etc...

0

Also loop through the amount of players when the player joins and then add them. From there use Players.PlayerAdded .

0

and if it finds the name is of that player then ignore it using else

0

U mean some loop that u dont shown in this script?

0

Because i only can see the loop that works only once, so new players cant be added to the list.

1 answer

✓ Accepted answer

Use coroutines. Coroutines basically create a new script that hides in nil that runs the data inside it's function so multiple things can be run at once.

1 comment

0

That was an intention I had, but I had no freaking idea how to run that function every time a player enteres.

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