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

Why does the GUI only clone once on join?

Asked by 8 years ago

I want this GUI from Workspace to clone into each player's PlayerGUI on join but right now it only clones to the player that most recently joined (when joined at the same time; tested via Roblox Studio->Test->Server->Two Players.

Players = game:GetService("Players")
joinGUI = script.Parent:Clone()
function onPlayerJoin(player)
    joinGUI.Parent = player.PlayerGui

end
Players.PlayerAdded:connect(onPlayerJoin)


Any help would be appreciated!

3 answers

Log in to vote
1
Answered by 8 years ago

Instead of playeradded function try this child added:

function onSpawn(Char)
if game.Players:FindFirstChild(Char.Name)~=nil then
    --code
end
end
game.Workspace.ChildAdded:connect(onSpawn)

So it would look like this:

Players = game:GetService("Players")
joinGUI = script.Parent:Clone()
function onSpawn(Char)
if game.Players:FindFirstChild(Char.Name)~=nil then
    joinGUI.Parent = player.PlayerGui
end
end
game.Workspace.ChildAdded:connect(onSpawn)

Hope this helped.

Ad
Log in to vote
0
Answered by 8 years ago

@Ghost, there's no reason to expand his code and use a hacky method for checking for a player. Just use the events roblox gives you:


Players = game:GetService("Players") function onPlayerJoin(player) local joinGUI = script.Parent:Clone() joinGUI.Parent = player.PlayerGui end Players.PlayerAdded:connect(onPlayerJoin)
Log in to vote
0
Answered by 8 years ago

I ended up just using StarterGUI with the option "ResetPlayerGuiOnSpawn" disabled.

Answer this question