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

Why does the GUI only clone once on join?

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

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.

@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)

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

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