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

How do I get a GUI to clone into the PlayerGui using a ClickDetector?

This is the current script I have and it is not working, I have it in a local script in a button.

workspace.Button.ClickDetector.Clicked:connect(function(plyr)
    if plyr == game.Players.LocalPlayer then
        workspace.Button.FlashGUI:Clone()["Parent"] = game.Players.LocalPlayer.PlayerGui
    end
end

Any help is always appreciated.

6 comments

0

You can't say ["Parent"], and can't use a LocalScript. Use a Server, .Parent, and get the PlayerGui like so: plyr.PlayerGui

0

I would suggest using a server script, just like Feahren pointed out, add it to player.PlayerGui.

0

So what I have is https://gyazo.com/a76a02c009685de31fcaa263f6d46838 and it still doesnt not work.

0

You can't use the LocalPlayer on Server because the Server doesn't have a LocalPlayer, quite logically. use game.Players[plyr] then

0

So im still trying and for some reason I can't get it to work. I've tried doing it several different ways, including the way you told me to do it and it still wont work.

0

You do not need to use ["Parent"] after the :Clone() function, as you can simply do :Clone().Parent

2 answers

I would suggest using a server script. Inside Clicked function you could do:

workspace.FlashGUI:Clone(plyr.PlayerGui)

1 comment

0

No. This is entirely wrong.

UPDATE:

I got it to work in a simple way using a LOCAL script. Heres the code:

local plyr = game.Players.LocalPlayer



function onClick()
	script.Parent.FlashGUI:Clone().Parent = plyr.PlayerGui
end

script.Parent.ClickDetector.MouseClick:Connect(onClick)

2 comments

0

I have a suggestion, its better to use game:GetService("Players").LocalPlayer than game.Players.LocalPlayer.

0

I have got it to actually work this time. Heres the full script: https://pastebin.com/BaZRQUHi

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