Opening Gui works only one time

I want to open and close an gui using an clicking detector and close it with an button gui , I want it client side , it work just once

open script (normal script):

local teams = game:GetService("Teams")
local team1 = teams.Teacher

game.Players.PlayerAdded:Connect(function(plr)
	if plr.Team == team1 then
		script.Parent.MouseClick:Connect(function()
		plr.PlayerGui.CanvasGui.Enabled = true
end)
end
end)

close script (local script):

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Parent.Enabled = false
end)

Im not sure but i think click detectors cant be used on local scripts if the parent is the click detector, try with a server script and check if it works.

Try this close script:

script.Parent.MouseButton1Click:Connect(function(plr)
	plr.PlayerGui.CanvasGui.Enabled = false
end)

image
its a server script

I mean the script to close the gui, not the open one.

so you say to put an Normal Script on an gui button?

or maybe this can be the close script if the I did above doesn’t work

local teams = game:GetService("Teams")
local team1 = teams.Teacher

game.Players.PlayerAdded:Connect(function(plr)
	if plr.Team == team1 then
		script.Parent.MouseClick:Connect(function()
		plr.PlayerGui.CanvasGui.Enabled = false
end)
end
end)

In your post said that you have 2 scripts, one is a server script, and another is a local script, try to change the local script to a server script.

ClickDetectors work perfectly fine on LocalScripts.

2 Likes

This works , thank you very much

1 Like