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

Turn On/Turn Off Window not working?

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.

function onClicked(playerWhoClicked)
    script.Parent.Transparency = 1 
	script.Parent.Parent.TurnOn.Decal.Transparency = 1
	function onClicked(ClickedAgain)
		script.Parent.Transparency = 0
		script.Parent.Parent.TurnOff.Decal.Transparency = 0
	end
end

script.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

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

      end
script.Parent.ClickDetector.MouseClick:conect(onClicked)
end

5 comments

0

:P

0

I meant you forgot to run the script

0

wait lol I meant you forgot to run the 2nd function

0

You can edit your answers and comments and stuff if you need to correct something, you know.

0

I did

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

script.Parent.ClickDetector.MouseClick:connect(function()
	if script.Parent.NumberValue.Value == 0 then
		script.Parent.Transparency = 1
		script.Parent.TurnOn.Decal.Transparency = 1
		script.Parent.NumberValue.Value = 1
	else 
		script.Parent.Transparency = 0
		script.Parent.TurnOn.Decal.Transparency = 0
		script.Parent.NumberValue = 0
end)

local Open = true

function onClicked(playerWhoClicked) -- If you don't want to know who clicked, you don't need this.
	script.Parent.Transparency = Open and 1 or 0 -- If open is true, then transparency is 1
	script.Parent.Parent.TurnOn.Decal.Transparency = Open and 1 or 0 -- If open is true, then transparency is 1
	Open = not Open -- Sets the value of open to it's opposite.
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

This should work.

1 comment

0

Edit: Changed "True" to "true"

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