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

This piece of code won't clone a gui into all player's PlayerGui?

Hi,

I modified a BTS Leaderboard script to use it as a gui results screen. I started a server of 2 in studio and executed this code. When this piece of code is executed, it clones a gui into one player's PlayerGui. Only one player's PlayerGui, no one else's. There is no errors even. I am so confused right now?

local msgui = WinGui:Clone()
for i, player in pairs(game.Players:GetChildren()) do
msgui.Parent = player.PlayerGui

1 answer

You made a copy in the first line.

Later, in the loop, you are moving that single copy. So it just ends up in the last player in the loop.

The fix is simple; just define msgui inside the loop so that a new one is made per player:

for i, player in pairs(game.Players:GetPlayers()) do
	local msgui = WinGui:Clone()
	msgui.Parent = player.PlayerGui
end

As a side note, it's recommended to use :GetPlayers() instead of :GetChildren() on the players service to get the list of playing players.

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