I cant make my switch script to work

So ive been making this script that goes into a proximityprompt. It make the prompt work as a switch that makes certain things invisible and play certain audios. And i have this other local script that goes inside an imagelabel in startergui that resets the parts to be visible again. I made this script check to see when a certain part is visible or not it will do the respective action. But even with that check it always does whatever the next part of the toggle. I beent rying to fix this for liek 5 hours and rescripting but i have no idea why i cant make ti work

local proximityPrompt = script.Parent -- Assuming the proximity prompt is a direct child of the part

local part1 = proximityPrompt.Parent.Switch -- Replace 'Switch' with the name of your first part
local part2 = proximityPrompt.Parent.Switch2 -- Replace 'Switch2' with the name of your second part

local beam1 = game.Workspace.BasementRooms.Server_Room.Damonitros.PCSCREEN1.Beam
local beam2 = game.Workspace.BasementRooms.Server_Room.Damonitros.PCSCREEN2.Beam
local beam3 = game.Workspace.BasementRooms.Server_Room.Damonitros.PCSCREEN3.Beam
local beam4 = game.Workspace.BasementRooms.Server_Room.Damonitros.PCSCREEN4.Beam
local beam5 = game.Workspace.BasementRooms.Server_Room.Damonitros.PCSCREEN5.Beam
local beam6 = game.Workspace.BasementRooms.Server_Room.Damonitros.PCSCREEN6.Beam

local screen1 = game.Workspace.BasementRooms.Server_Room.Damonitros.Screen1
local screen2 = game.Workspace.BasementRooms.Server_Room.Damonitros.Screen2
local screen3 = game.Workspace.BasementRooms.Server_Room.Damonitros.Screen3
local screen4 = game.Workspace.BasementRooms.Server_Room.Damonitros.Screen4
local screen5 = game.Workspace.BasementRooms.Server_Room.Damonitros.Screen5
local screen6 = game.Workspace.BasementRooms.Server_Room.Damonitros.Screen6

local audio = game.Workspace.Audio.switch1
local audio2 = game.Workspace.Audio.switch12

local cooldown = 1
local canToggle = true

-- BoolValue to control the state
local isScriptEnabled = script:WaitForChild("IsEnabled", 2) or Instance.new("BoolValue")
isScriptEnabled.Name = "IsEnabled"
isScriptEnabled.Value = true
isScriptEnabled.Parent = script

-- Function to toggle transparency
local function toggleTransparency()
	if canToggle then
		canToggle = false

		if part1.Transparency == 0 then
			part1.Transparency = 1
			part2.Transparency = 0

			audio.Playing = true

			screen1.Color = Color3.new(0.105882, 0.164706, 0.207843)
			screen2.Color = Color3.new(0.105882, 0.164706, 0.207843)
			screen3.Color = Color3.new(0.105882, 0.164706, 0.207843)
			screen4.Color = Color3.new(0.105882, 0.164706, 0.207843)
			screen5.Color = Color3.new(0.105882, 0.164706, 0.207843)
			screen6.Color = Color3.new(0.105882, 0.164706, 0.207843)

			beam1.Enabled = false
			beam2.Enabled = false
			beam3.Enabled = false
			beam4.Enabled = false
			beam5.Enabled = false
			beam6.Enabled = false
		elseif part1.Transparency == 1 then
			part1.Transparency = 0
			part2.Transparency = 1

			audio2.Playing = true

			screen1.Color = Color3.new(0.172549, 0.396078, 0.113725)
			screen2.Color = Color3.new(0.172549, 0.396078, 0.113725)
			screen3.Color = Color3.new(0.172549, 0.396078, 0.113725)
			screen4.Color = Color3.new(0.172549, 0.396078, 0.113725)
			screen5.Color = Color3.new(0.172549, 0.396078, 0.113725)
			screen6.Color = Color3.new(0.172549, 0.396078, 0.113725)

			beam1.Enabled = true
			beam2.Enabled = true
			beam3.Enabled = true
			beam4.Enabled = true
			beam5.Enabled = true
			beam6.Enabled = true
		end

		wait(cooldown)
		canToggle = true
	end
end


proximityPrompt.Triggered:Connect(toggleTransparency)

Is there any errors in the console?
Haven’t really tried to test this but try this
I also optimized it so its easier for me to fix

local proximityPrompt = script.Parent -- Assuming the proximity prompt is a direct child of the part

local part1 = proximityPrompt.Parent.Switch -- Replace 'Switch' with the name of your first part
local part2 = proximityPrompt.Parent.Switch2 -- Replace 'Switch2' with the name of your second part
local ScreenPlace =  game.Workspace.BasementRooms.Server_Room.Damonitros

local audio = game.Workspace.Audio.switch1
local audio2 = game.Workspace.Audio.switch12

local cooldown = 1
local canToggle = true

-- BoolValue to control the state
local isScriptEnabled = script:WaitForChild("IsEnabled", 2) or Instance.new("BoolValue")
isScriptEnabled.Name = "IsEnabled"
isScriptEnabled.Value = true
isScriptEnabled.Parent = script

-- Function to toggle transparency
local function toggleTransparency()
	if canToggle then
		canToggle = false

		if part1.Transparency == 0 then
			part1.Transparency = 1
			part2.Transparency = 0

			audio:Play()
			for i, screen in ScreenPlace:GetDescendants() do
				if screen:IsA("Part") then
					screen.Color = Color3.new(0.105882, 0.164706, 0.207843)
				end
			end
			for i, beam in ScreenPlace:GetDescendants() do
				if beam:IsA("Beam") then
					beam.Enabled = false
				end
			end

		else
			part1.Transparency = 0
			part2.Transparency = 1

			audio2:Play()

			for i, screen in ScreenPlace:GetDescendants() do
				if screen:IsA("Part") then
					screen.Color = Color3.new(0.172549, 0.396078, 0.113725)
				end
			end
			for i, beam in ScreenPlace:GetDescendants() do
				if beam:IsA("Beam") then
					beam.Enabled = true
				end
			end

		end

		task.wait(cooldown)
		canToggle = true
	end
end


proximityPrompt.Triggered:Connect(toggleTransparency)

I’ll take a shot at it … :slight_smile:

local p, p1, p2 = script.Parent, script.Parent.Switch, script.Parent.Switch2
local cooldown, canToggle = 1, true

local beams = {}
local screens = {}

for i = 1, 6 do
    beams[i] = game.Workspace.BasementRooms.Server_Room.Damonitros["PCSCREEN" .. i].Beam
    screens[i] = game.Workspace.BasementRooms.Server_Room.Damonitros["Screen" .. i]
end

local audio, audio2 = game.Workspace.Audio.switch1, game.Workspace.Audio.switch12

local isScriptEnabled = script:WaitForChild("IsEnabled", 2) or Instance.new("BoolValue")
isScriptEnabled.Name, isScriptEnabled.Value, isScriptEnabled.Parent = "IsEnabled", true, script

local function toggleTransparency()
	if canToggle then
		canToggle = false
		local t1, t2 = part1.Transparency, part2.Transparency

		if t1 == 0 then
			part1.Transparency, part2.Transparency = 1, 0
			audio.Playing = true
		elseif t1 == 1 then
			part1.Transparency, part2.Transparency = 0, 1
			audio2.Playing = true
		end

		for _, scr in ipairs(screens) do
			scr.Color = t1 == 0 and Color3.new(0.105882, 0.164706, 0.207843) or Color3.new(0.172549, 0.396078, 0.113725)
		end

		for _, b in ipairs(beams) do
			b.Enabled = t1 == 0
		end

		wait(cooldown)
		canToggle = true
	end
end

proximityPrompt.Triggered:Connect(toggleTransparency)

If you want the local script for the Image Button, to work for all players you’ll want the local script to fire an event. Make a new event and place it in ReplicatedStorage, and make a new script in ServerScriptService, and make that script make the parts visible again whenever it detects the event being fired. Easiest way to make it work for every player. For your other issue, I’m still trying to make a solution.