GUI:Clone from replicatedstorage doesn't work?

Hey,

I am trying to clone a GUI from replicated storage to a PlayerGUI.

Script

My script for cloning
local player = game.Players.LocalPlayer --Variable for the player

local GUI = game.ReplicatedStorage.Register --Variable for the gui

function clone()

GUI:Clone().Parent = player.PlayerGui

end

script.Parent.MouseButton1Click:Connect(clone)
Explorer

Error: Workspace.Part.SurfaceGui.TextButton.Script:5: attempt to index nil with ‘PlayerGui’ - Server - Script:5

I hope someone can help me, thanks.

LocalPlayer does not work in regular scripts, since you’re using a SurfaceGui. Do this

  • Put the SurfaceGui in StarterGui and set the Adornee property of the SurfaceGui to be the Part you want it to display on

  • Change the regular script to a LocalScript

Oh alright, I changed that but it seem to not work yet. If I debug (using print) I get it in my console.

What needs to be changed?

What’s your current explorer view on everything related to this?

This is my current explorer.

Did you remember to set the Adornee to the part to display the SurfaceGui on? Maybe try this if you did that?

local player = game:GetService("Players").LocalPlayer --Variable for the player
local playerGui = player:WaitForChild("PlayerGui")
local GUI = game:GetService("ReplicatedStorage").Register --Variable for the gui

script.Parent.MouseButton1Click:Connect(function()
	GUI:Clone().Parent = playerGui
end)

Oml, I forgot to enable the GUI. This works, thanks :smiley:

1 Like

Haha It’s okay! Sometimes we don’t realise simple mistakes until we look closer!

If you have anymore isuses don’t be afraid to make another post!

1 Like