Light2 is not a valid member of Workspace "Workspace"

Hello! I am making a FNAF game and I spent about 30 minutes trying to fix this issue. The first light button works but the second one is always having problems.

local LightButton = game.Workspace.LightButton
local DoorButton = game.Workspace.DoorButton
local LightOnValue = script["LightOn?"].Value
local DoorLight = game.Workspace.DoorLight
local LightButton2 = game.Workspace.LightButton2
local DoorButton2 = game.Workspace.DoorButton2
local LightOnValue2 = script["LightOn?2"]
local DoorLight2 = game.Workspace.DoorLight2
local DoorButton = game.Workspace.DoorButton
local DoorButton2 = game.Workspace.DoorButton2

function Light()
	local LightPart = script.Light:Clone()
	if LightOnValue == 0 then
		LightOnValue = 1
		LightPart.Parent = game.Workspace
		DoorLight.Parent = script
		script.Parent.PowerUsage.Value = script.Parent.PowerUsage.Value + 1
	else
		LightOnValue = 0
		game.Workspace.Light:Destroy()
		script.DoorLight.Parent = game.Workspace
		script.Parent.PowerUsage.Value = script.Parent.PowerUsage.Value - 1
	end
end

LightButton.ClickDetector.MouseClick:Connect(Light)

function Light2()
	local LightPart2 = script.Light2:Clone()
	if LightOnValue2 == 0 then
		LightOnValue2 = 1
		LightPart2.Parent = game.Workspace
		DoorLight2.Parent = script
		script.Parent.PowerUsage.Value = script.Parent.PowerUsage.Value + 1
	else
		LightOnValue2.Value = 0
		game.Workspace.Light2:Destroy()
		script.DoorLight2.Parent = game.Workspace
		script.Parent.PowerUsage.Value = script.Parent.PowerUsage.Value - 1
	end
end

LightButton2.ClickDetector.MouseClick:Connect(Light2)
1 Like

Im reviewing your code but
instead of writing a function then connecting it like that
do this

LightButton2.ClickDetector.MouseClick:Connect(function()
-- your code here
end)

Update found it
When declaring lightonvalue2 you didnt set it to the value instead instance.