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

Need a little help with activating a GUI by using ClickDetector - why won't it work?

First of all, salutations. I've tried everything I could to get this work, and it's probably one of the more simple things I've come across with scripting - for some reason, it just won't work. The script is a LocalScript located within a static NPC's head, along with a ClickDetector. I've also tried a script that makes the Frame of the GUI visible when clicked on, but that didn't work either.

local GuiSet = game.ServerStorage:WaitForChild("squest1")

script.Parent.ClickDetector.MouseClick:Connect(function()	
	local a = GuiSet:Clone()
	a.Parent = game.Players.LocalPlayer.PlayerGui
end)

This script's intended purpose is to make a GUI appear. The GUI then gives the player a part of a gun for an in-game sidequest. When clicked, nothing happens. at all. So if you guys could help point me in the right direction, it'd be much appreciated. Thanks in advance.

1 answer

✓ Accepted answer

Local scripts don't run MouseClick functions. You can also get the player's name from the function by putting playerWhoClicked or just simply player.

Final script:

local GuiSet = game.ServerStorage:WaitForChild("squest1")

script.Parent.ClickDetector.MouseClick:Connect(function(player)  
    local a = GuiSet:Clone()
    a.Parent = game.Players:FindFirstChild(player.Name).PlayerGui
end)

If this works please give a upvote and accept the answer!

Wiki Resource(s):

ROBLOX Wiki - Making an onClicked script

ROBLOX Wiki - API:Class/ClickDetector/MouseClick

1 comment

0

Thank you so much!

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