Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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.

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) KentrusWoW 0 — 5y
0
Don't forget to accept the answer if it helped you so we can both earn some reputation points. Zafirua 1348 — 5y

1 answer

Log in to vote
1
Answered by
Zafirua 1348 Badge of Merit Moderation Voter
5 years ago
Edited 5 years ago

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);
0
correct User#19524 175 — 5y
Ad

Answer this question