So I am a bit stuck here. How do I use a clickdetector to open a GUI. The GUI is called NameSetGUI
--Local Script
local Frame = yourpathway
local open = false
script.Parent.MouseButton1Click:Connect(function()
if Frame.Visible == false then
Frame.Visible = true
else
Frame.Visible = true
end
end)
Sorry I mean a ScreenGUI. It’s for a quiz show “The Chase” to set the names on the team desk.
oh ok hold on this will be quick
Script inside Clickdetector
script.Parent.MouseClick:Connect(function(plr)
plr:WaitForChild("PlayerGui").NameSetGUI.Visible = true
end)
oh that’s what he meant ok i see now
Is this a normal script or local?
Ok so the script works but I can’t reopen it after closing it (I have a close button inside the GUI that hides the frame)
script.Parent.MouseClick:Connect(function(plr)
if plr:WaitForChild("PlayerGui").NameSetGUI.Visible == true then
plr:WaitForChild("PlayerGui").NameSetGUI.Visible = false
else
plr:WaitForChild("PlayerGui").NameSetGUI.Visible = true
end
end)
That occurs because from the server’s perspective the GuiObject is still visible as it has only been hidden on the client, and typically, client-side changes do not replicate to the server. We can circument this issue through the use of a RemoteEvent instance which will ensure that all changes occur on the client only.
--SERVER
local click = script.Parent
local replicated = game:GetService("ReplicatedStorage")
local remote = replicated.RemoteEvent
click.MouseClick:Connect(function(player)
remote:FireClient(player)
end)
--CLIENT
local frame = script.Parent
local replicated = game:GetService("ReplicatedStorage")
local remote = replicated:WaitForChild("RemoteEvent")
remote.OnClientEvent:Connect(function()
frame.Visible = true
end)
The server script should go inside the ClickDetector, the local script should go inside the Frame which has its visibility toggled and the RemoteEvent should go inside the ReplicatedStorage container.
Hi. This one didn’t work sorry.
It worked for me so your implementation must have been wrong.
a.rbxl (29.0 KB)
In future you should thoroughly verify that someone’s code doesn’t work before stating as such.
I have checked the script and they are identical, I am unsure what went wrong.
Got it sorted now. Thanks for your help. I added something wrong.