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

ClickDetector only opens GUI once when I click it...?

I would simply like the ClickDetector to open my GUI, and then the GUI can be disabled by a button. But when I try to click the ClickDetector one more time (after I closed the GUI), it doesn't work.

Part ClickDetector Code (Script):

script.Parent.ClickDetector.MouseClick:connect(function(player)
    player.PlayerGui.ProductShop.Enabled = true
end)

GUI Close Button Code (LocalScript):

local s = script.Parent 
s.MouseButton1Down:connect(function()
    s.Parent.Parent.Enabled = false
end)

Any help would be appreciated.

1 comment

0

use remote events.. i think?

1 answer

✓ Accepted answer

ServerScripts can't look inside the PlayerGui. To open a gui in PlayerGui with a ServerScript you have to use a RemoteEvent (at least it's the only way I know). So start with adding a RemoteEvent in to ReplicatedStorage and then write this code in your ServerScript, which I believe is located in a part with a ClickDetector:

local remEvent = game.ReplicatedStorage:WaitForChild("RemoteEvent")
script.Parent.ClickDetector.MouseClick:Connect(function(player)
remEvent:FireClient(player)
end)

Make a new LocalScript in the gui and write this code:

local remEvent = game.ReplicatedStorage:WaitForChild("RemoteEvent")
remEvent.OnClientEvent:Connect(function()
script.Parent.Enabled = true
end)

Hope it helped!

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