I have a part of a server script that is meant to go into a players PlayerGui when they join, delete a certain GUI. It is then meant get a random player from the server, and clone their gui into that players gui but it can’t find PlayerGui in the player. Just get the infinite yield error for WaitForChild. Anyone know why?
Players.PlayerAdded:Connect(function(player)
player.PlayerGui:WaitForChild("Menu"):Destroy()
local Copy = randomPlayer:WaitForChild("PlayerGui"):WaitForChild("Menu"):Clone()
Copy.Parent = player:WaitForChild("PlayerGui")
end)
Try using WaitForChild on the PlayerGui, Not sure if that’ll make it work. The PlayerGui usually takes some time to Replicate, So i guess waiting for it might be the solution.
I have a team creation/selection ui, not really sure the best way to do it, tried 3 other methods and what I’m doing is the only one which allows everything to work, the server script isn’t actually changing the ui, it’s just doing commanding what happens and sending remote events to the local script that changes the ui. I thought that maybe it was saying that because maybe the PlayerGui just hadn’t been loaded by the time it checks so I delayed it and still got it.
The code you sent appears to just put things into the player’s PlayerGui, and there’s no reference of remotes in the 5 lines of code you gave us. Why isn’t the UI in the PlayerGui in the first place?
That’s just the function that is supposed to update the new players gui, didn’t really think it was necessary to include the entire script seeing that the rest of the script doesn’t interact with that function at all.
Just store whatever edits players have made in ReplicatedStorage, and apply them whenever someone gets picked. Or, have a localscript clone the UI from ReplicatedStorage and put it under the LocalPlayer when the player gets picked.