Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
1

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

Asked by 2 months ago

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.

0
use remote events.. i think? CjayPlyz 442 — 2mo

1 answer

Log in to vote
1
Answered by 2 months ago

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!

Ad

Answer this question