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

How do I make this script not run when my gui is already active? [SOLVED]

I have these 2 scripts that make when a part is touched it opens up a gui.
LocalScript:

local gui = script.ScreenGui
local brickTouchedEvent = game.ReplicatedStorage.Events.BrickTouched
local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local char = player.Character or player.CharacterAdded:Wait()
brickTouchedEvent.OnClientEvent:Connect(function()
	gui.Enabled = true
	gui.Frame.bmw.GoLeftShowHOON.Visible = true
	gui.Frame.bmw.GoRightShowPOR.Visible = true
	gui.Frame.Close.Visible = true
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = workspace.Cameras.BMWPart.CFrame
	char.Humanoid.WalkSpeed = 0
	end)
    gui.Frame.Close.MouseButton1Click:Connect(function()
		if camera.CameraType ~= Enum.CameraType.Custom then
		repeat wait()
			camera.CameraType = Enum.CameraType.Custom
		until camera.CameraType == Enum.CameraType.Custom
	end
	camera.CameraSubject = char
	char.Humanoid.WalkSpeed = 16
	gui.Enabled = false
	wait(4)
end)

Normal script:

local brick = script.Parent
local brickTouchedEvent = game.ReplicatedStorage.Events.BrickTouched
local debounce = false
brick.Touched:Connect(function(hit)
	if not debounce then
		debounce = true
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		brickTouchedEvent:FireClient(player)
		print(player.Name.."opened the gui!")
		wait(4)
		debounce = false
	end
end)

Now, I have a probem wich is when 4 seconds passes it opens the gui again so if I went to the other camera and textbuttons it woud reset to the camera and textbuttons that come up when the gui is active, and I don't know what should I use since I can't check if my gui is already active or not.

1 answer

Ok, I actually fixed it real quick, I was thinking about it for 4 days but this is how I solved (in the localscript btw):

local gui = script.ScreenGui
local brickTouchedEvent = game.ReplicatedStorage.Events.BrickTouched
local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local char = player.Character or player.CharacterAdded:Wait()
brickTouchedEvent.OnClientEvent:Connect(function()
	gui.Enabled = true
	gui.Frame.bmw.GoLeftShowHOON.Visible = true
	gui.Frame.bmw.GoRightShowPOR.Visible = true
	gui.Frame.Close.Visible = true
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = workspace.Cameras.BMWPart.CFrame
	char.Humanoid.WalkSpeed = 0
	script.Disabled = true -- Disables the script so it can't run again
	end)
    gui.Frame.Close.MouseButton1Click:Connect(function()
		if camera.CameraType ~= Enum.CameraType.Custom then
		repeat wait()
			camera.CameraType = Enum.CameraType.Custom
		until camera.CameraType == Enum.CameraType.Custom
	end
	camera.CameraSubject = char
	char.Humanoid.WalkSpeed = 16
	gui.Enabled = false
	wait(4)
	script.Disabled = false -- Enables the script so it can run again
end)

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