Expected identifier when parsing expression, got )

I’ve got this script here which is supposed to turn on and off these Emergency Lights when my EmergencyAlarms BoolValue get’s changed.

But my problem is that it keeps complaining about my end) and everything I seem to do, doesn’t fix it any help appreciated, thanks!

workspace.GameValues.EmergencyAlarms.Changed:Connect(function()
	if workspace.GameValues.EmergencyAlarms == true then
		for i,v in pairs(game.Workspace:GetChildren()) do
			if v.Name == "EmergencyLight" then
				v.Toggle = true
			end
		end
		else
			for i,v in pairs(game.Workspace:GetChildren()) do
				if v.Name == "EmergencyLight" then
					v.Toggle = false
				end	
		end	
	end)

Reference workspace.GameValues.EmergencyAlarms.Value as it’s a boolvalue, you’re currently referencing instance == true.

You might also simplify the loop since you’re comparing boolean == true → .Toggle = true, else .Toggle = false, so you could just do:

workspace.GameValues.EmergencyAlarms.Changed:connect(function()
	for _, v in pairs(workspace:GetChildren()) do
		if v.Name == "EmergencyLight" then
			v.Toggle = workspace.GameValues.EmergencyAlarms.Value
		end
	end
end)
1 Like

You just need an end to close off one of your statements.

workspace.GameValues.EmergencyAlarms.Changed:Connect(function()
	if workspace.GameValues.EmergencyAlarms == true then
		for i,v in pairs(game.Workspace:GetChildren()) do
			if v.Name == "EmergencyLight" then
				v.Toggle = true
			end
		end
	else
		for i,v in pairs(game.Workspace:GetChildren()) do
			if v.Name == "EmergencyLight" then
				v.Toggle = false
			end	
		end	
	end
end)
2 Likes

Thanks for both of your answers just had to change v.Toggle to v.Toggle.Value for MP3Face’s, and Phenomenality’s answer would have worked too, with the same change, thanks!