Can't clone a folder into PlayerGui

Hello! I am trying to clone a folder inside playerGui from a local script, but its not being cloned

The code is this

local player = game:GetService("Players").LocalPlayer
local replicated = game:GetService("ReplicatedFirst")

local SpawnUis = replicated.SpawnUis:Clone()

SpawnUis.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")

But when i add wait() it magically works, like

local player = game:GetService("Players").LocalPlayer
local replicated = game:GetService("ReplicatedFirst")

local SpawnUis = replicated.SpawnUis:Clone()

wait(1)
SpawnUis.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")

but i dont want to use wait() because of a potential laggy player. Also i dont understand why i can’t assign it’s parent instantly and instead i have to wait a second.
First i thought maybe i have to wait for playergui to load but even then it doesn’t work

3 Likes

Try that:

local playerguifound = game.Players.LocalPlayer:FoundFirstChild("PlayerGui")
if playerguifound then

SpawnUis.Parent = playerguifound

If it’s not working tell me.

1 Like

Sadly it didn’t work. I even added a print statement somehow the print works but setting the parent dont

you can’t create new guis on the client and have them visible

you should use a server script

the way how playergui works is:
server has the gui, sends a copy to each client that joins the game
you can only add new UI via server, but you can customize the already existing UI via client

Have you tried awaiting the SpawnUis UI?

Yes that makes sense but i am not creating a new gui i am copying one and it somehow works when i add wait function for a second. If i parent everything to the playergui then there is another bug where i cant access the spawnui inside playergui even with waitforchild() and i again need to add wait. I wanted to have a workaround by parenting it to replicatedfirst so it loads first and then parent it to player but as you can see with the post, i get a similar problem. I can of course just add wait and skip the hassle but i dont think it’s reliable

Sharing out what console printed might help, Maybe it’s saying something like infinite possible yields like that.

Yes i did at first and it was the same problem, but its in replicated first so logically it should be loaded before the script can access

actually wait, i think:

local RF = game:GetService("ReplicatedFirst")
local plr = game:GetService("Players").LocalPlayer
local plrGui = plr:WaitForChild("PlayerGui") -- or plr:FindFirstChild("PlayerGui")

local SpawnUis = RF:WaitForChild("SpawnUis"):Clone() -- this could yield infinitely so i apologize

SpawnUis.Parent = plrGui

if this doesn’t work then i suggest doing it via server, or just doing it in startergui

Oh sorry i forgot about adding the console but no there is no infinite yield i also added a print after assigning the parent and it works so i suppose there is no yield?

technically that is creating a new gui :smiley:

i honestly just suggest doing it on the server

GUIs are best done on client but not on server as this can create response lag.

it also didn’t work there was no yielding too but when i added wait before the parent assigning that again worked

Also try printing out print(SpawnUis.Parent), This may tell you something whats happening.

Oops, yeah i guess i’ll do that i just didn’t want to divide the code

what kind of response lag? who put this stupid character limit iaeyjhgdoifd

Oh that makes sense! Just did that and it says it’s in playergui but there is no folder inside playergui when i check it? This confused me more

You may wanna debug the values of different objects by printing out values and then post your new script with prints and output.

local RF = game:GetService("ReplicatedFirst")
local plr = game:GetService("Players").LocalPlayer
local plrGui = plr:WaitForChild("PlayerGui") -- or plr:FindFirstChild("PlayerGui")
print(plrGui) -- nil
local SpawnUis = RF:WaitForChild("SpawnUis"):Clone()
print(SpawnUis) -- SpawnUi

SpawnUis.Parent = plrGui
print(plrGui:FindFirstChild(SpawnUis)) -- nil
print(SpawnUis.Parent) --playergui

this doesn’t make sense tho how can the parent be playergui while not being able to access it inside the said playergui?

If you wont mind if you can share the rbxl place file and let me look into it, this is confusing ngl.