✓ Accepted answer
You're very close to the answer with this script, there's just a small error. Basically, rather than assigning >lighton to an integer, you want to create a Boolean (a value that can only be true or false). If we change this, your script should work:
local door = game.Workspace.RDoor
local clickDetector = Instance.new("ClickDetector")
clickDetector.Parent = script.Parent
local lighton = false
function light()
print("light")
if lighton == false then
door.Transparency = 1
lighton = true
end
if lighton == true then
door.Transparency = 0
lighton = false
end
end
clickDetector.MouseClick:Connect(light)
Ok, our script is working. But believe it or not, we can simplify this, which you should always try to do, as it saves you work.
local door = game.Workspace.RDoor
local clickDetector = Instance.new("ClickDetector")
clickDetector.Parent = script.Parent
local lighton = false
function light()
print("light")
if lighton then
door.Transparency = 0
lighton = false
else
door.Transparency = 1
lighton = true
end
end
clickDetector.MouseClick:Connect(light)
As you can see, there is less to type out now. What i've done is simple, for starters (we'll look at Fig.A) since our >lighton value is now a boolean, it's only ever going to be true or false right? And an if statement is going to execute the code within if the condition >lighton are true, if you look at Fig.B now, you'll see that i've changed your code a bit.
Basically, if >lighton is not true, then do whats within the else statement. Now we're talking. If you really wanted to you could shorten this code even further, but that isn't necessary so i'll leave that for another time.
Useful Links:
Conditional Statements (I recommend looking at Else and ElseIf statements.)
Booleans
4 comments
This answer is better :3
Although, i'm pretty sure you can just do, door.Transparency = -(door.Transparency -1)
well its the same thing but i guess we are going for minimalist code here lol
exactly, programmers are lazy ;3