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

How to clone GUI from RepStor to PlayerGui?

local FlyGUI = "FlyGUI"

if (game.Players.LocalPlayer.PlayerGui:GetChildren("FlyGUI") == nil) then
		if (game.Players.LocalPlayer.PlayerGui:GetChildren("FlyGUI") ~= nil) then game:GetService("ReplicatedStorage").FlyGUI:clone().Parent = game.Players.LocalPlayer.PlayerGui
			end
		end

Not exactly sure what I am doing wrong here.

1 answer

#Problems

There are a few errors in your code.. i'll walk you through them.

    1. The GetChildren function returns a table of the specified object's descendants. The function you're looking for is the FindFirstChild function.
    1. You have 2 contradicting if statements. You should omit the second one from your code
    1. When you reference the 'FlyGUI', you should reference the actual object rather than a string representing the object. It saves you the need to search for the item.

#####note: remember to use variables to keep your code clean and readable!


#Code

local player = game.Players.LocalPlayer --Variable for the player
local FlyGUI = game.ReplicatedStorage.FlyGui --Variable for the gui

if not player.PlayerGui:FindFirstChild(FlyGUI.Name) then
	FlyGUI:Clone().Parent = player.PlayerGui --Clone gui to player
end

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