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

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

Asked by 9 years ago

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

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

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.

Ad

Answer this question