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

Turn On/Turn Off Window not working?

Asked by 10 years ago

So I am making something like a reception desk. The person manning the desk can click the window to make it transparent or not. It would also label "Click to start(/end) interviews" to prompt the player to open the window if they are ready for an interview.

01function onClicked(playerWhoClicked)
02    script.Parent.Transparency = 1
03    script.Parent.Parent.TurnOn.Decal.Transparency = 1
04    function onClicked(ClickedAgain)
05        script.Parent.Transparency = 0
06        script.Parent.Parent.TurnOff.Decal.Transparency = 0
07    end
08end
09 
10script.Parent.ClickDetector.MouseClick:connect(onClicked)

I don't know how to make it work. It would go transparent, but if you click it again, it wouldn't work.

3 answers

Log in to vote
1
Answered by 10 years ago

The problem is in the last lines you forgot to run the 2nd function

1      end
2script.Parent.ClickDetector.MouseClick:conect(onClicked)
3end
0
:P chill22518 145 — 10y
0
I meant you forgot to run the script chill22518 145 — 10y
0
wait lol I meant you forgot to run the 2nd function chill22518 145 — 10y
0
You can edit your answers and comments and stuff if you need to correct something, you know. Lightdrago 95 — 10y
0
I did chill22518 145 — 10y
Ad
Log in to vote
1
Answered by 10 years ago

You could use a numbervalue in the brick. In my opinion, that would be easier. It could look like this:

01script.Parent.ClickDetector.MouseClick:connect(function()
02    if script.Parent.NumberValue.Value == 0 then
03        script.Parent.Transparency = 1
04        script.Parent.TurnOn.Decal.Transparency = 1
05        script.Parent.NumberValue.Value = 1
06    else
07        script.Parent.Transparency = 0
08        script.Parent.TurnOn.Decal.Transparency = 0
09        script.Parent.NumberValue = 0
10end)
Log in to vote
1
Answered by
iaz3 190
10 years ago
1local Open = true
2 
3function onClicked(playerWhoClicked) -- If you don't want to know who clicked, you don't need this.
4    script.Parent.Transparency = Open and 1 or 0 -- If open is true, then transparency is 1
5    script.Parent.Parent.TurnOn.Decal.Transparency = Open and 1 or 0 -- If open is true, then transparency is 1
6    Open = not Open -- Sets the value of open to it's opposite.
7end
8 
9script.Parent.ClickDetector.MouseClick:connect(onClicked)

This should work.

0
Edit: Changed "True" to "true" iaz3 190 — 10y

Answer this question