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

How to clone GUI from RepStor to PlayerGui?

Asked by 7 years ago
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

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

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.

  • 2) You have 2 contradicting if statements. You should omit the second one from your code

  • 3) 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
Ad

Answer this question