How would I make it so a GUI doesn't appear the second time after clicking a ClickDetector?

Could you post the scripts you’ve got here now, both the server one and the client one?

Button Script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local LockdownEvent = ReplicatedStorage:WaitForChild("LockdownEvent")

local function onLockdownEvent(action)
	if action == "start" then
		game.StarterGui.ScreenGui.Frame.Visible = true
	end

	if action == "end" then
		game.StarterGui.ScreenGui.Frame.Visible = false
	end
end

LockdownEvent.OnClientEvent:Connect(onLockdownEvent)

Gui Script

local button = game.Workspace.LockdownButton
local object = script.Parent
local clickdetector = button.ClickDetector


function onMouseClick(player)
	wait(2)
	object.AnchorPoint = Vector2.new(0, 0)
	object.Position = UDim2.new(0.386, 0, -0.3, 0)
	wait(0.5)
	object:TweenPosition(UDim2.new(0.386, 0, 0, 0), 'Out', 'Quint', '4')
end



clickdetector.MouseClick:connect(onMouseClick)

Event Script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local LockdownEvent = ReplicatedStorage:WaitForChild("LockdownEvent")

local function onLockdownEvent(action)
	if action == "start" then
		game.StarterGui.ScreenGui.Frame.Visible = true
	end

	if action == "end" then
		game.StarterGui.ScreenGui.Frame.Visible = false
	end
end

LockdownEvent.OnClientEvent:Connect(onLockdownEvent)

Lockdown script

local sound = Instance.new("Sound", game.Workspace)
local reverb = Instance.new("ReverbSoundEffect", game.Workspace.Sound)
reverb.WetLevel = "-13"
sound.SoundId = "rbxassetid://4621098419"

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local LockdownEvent = ReplicatedStorage:WaitForChild("LockdownEvent")

local LockdownButton = script.Parent
local clickDetector = LockdownButton.ClickDetector
local clicked = false
local lights = game.Workspace.Lights

function onMouseClick()
	if not clicked then 
		clicked = true 
		
		LockdownButton.BrickColor = BrickColor.Red()
		sound.SoundId = "rbxassetid://4621098419"
		sound.Playing = true
			wait(9)
			sound.Playing = false
			sound.SoundId = "rbxassetid://394634971"
			sound.Looped = true
			sound.Playing = true
		for k, light in pairs(lights:getChildren()) do
			light.Light.Color= Color3.fromRGB(255, 58, 58)
		end
		LockdownEvent:FireAllClients("start")
	else
		clicked = false
		LockdownButton.BrickColor = BrickColor.Green()
		sound.Playing = false
		sound.SoundId = "rbxassetid://1526192493"
		sound.Playing = true
		wait(4)
		sound.Playing = false
		for k, light in pairs(lights:getChildren()) do
		   light.Light.Color= Color3.fromRGB(255, 255, 255)
		end
		LockdownEvent:FireAllClients("end")
	end
end

clickDetector.MouseClick:connect(onMouseClick)

GUI Code

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local LockdownEvent = ReplicatedStorage:WaitForChild("LockdownEvent")

local object = script.Parent

local function onLockdownEvent(action)
  if action == "start" then
	object.Visible = true
   	object.AnchorPoint = Vector2.new(0, 0)
	object.Position = UDim2.new(0.386, 0, -0.3, 0)
	wait(.5)
	object:TweenPosition(UDim2.new(0.386, 0, 0, 0), 'Out', 'Quint', '4')
  end

  if action == "end" then
    	object.Visible = false
  end
end

LockdownEvent.OnClientEvent:Connect(onLockdownEvent)

Try testing this
It’s what @TongyTwo explained

2 Likes

Yes that looks like what I was thinking of
You’d also need to remove the GuiScript that currently handles the click detector, you won’t want that any more

1 Like