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

Light and Light Switch ' then ' and identifier issue. What is an identifier???

Script Purpose: To make a light activate from a switch. Script: local BathLightCD = script.Parent.ClickDetector

BathLightCD.MouseClick:Connect(function(Clicked)
game.Workspace.BathroomLight.Light.PointLight.Brightness = 10
if BathLightCD.RightMouseClick:Connect(function(Clicked) do
game.Workspace.BathroomLight.Light.PointLight.Brightness = 0

	
end

end)


Notes: The point is it's talking about using ' then ' just when I do it wants me to use an identifier which I don't know what that is. Please help.

2 comments

0

local BathLightCD = script.Parent.ClickDetector BathLightCD.MouseClick:Connect(function(Clicked) game.Workspace.BathroomLight.Light.PointLight.Brightness = 10 if BathLightCD.RightMouseClick:Connect(function(Clicked) do game.Workspace.BathroomLight.Light.PointLight.Brightness = 0 end end)

0

Don't forget to accept the answer if it helped you so we can both earn some reputation points.

1 answer

Firstly, the syntax for conditional statement is if .. then not if .. do. The compiler was throwing you error because if.. do does not exist.

Secondly, You are creating a new function in the if statement. This is bound to throw you another error. Instead, you want to check if the Light's Brightness is either 10 or 0. Also note that you do not need a parameter in the function.

-- [Declaration Section]
--\\ Part Location
local Baseplate         = workspace.Baseplate;
local Light             = Baseplate.PointLight;
local ClickDetector     = Baseplate.ClickDetector;

-- [Processing Section]
local function ChangeLight ()
	if Light.Brightness == 0 then 
		Light.Brightness = 10;
		print(Light.Brightness);
	else 
		Light.Brightness = 0;
		print(Light.Brightness);
	end;
end;

-- [Connecting Section]
ClickDetector.MouseClick:Connect(ChangeLight);

1 comment

0

correct

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