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

How do I make my script wait for a player to click again to change the transparency of unions?

This question is somewhat similar to my last but my issue now is that I am unaware of how to connect my script to wait for a player to click the Click Detector in the brick to change the transparency of multiple unions to 1 instead of one union out of all of them. This may sound confusing but look at the script and I will explain in more detail:

local ClickHere = script.Parent.Parent.ClickHere
local PlateEmp = script.Parent.Parent.PlateEmp
local PlateInv = script.Parent.Parent.PlateInv
local Plate1 = script.Parent.Parent.Plate1
local Plate2 = script.Parent.Parent.Plate2
local Plate3 = script.Parent.Parent.Plate3

function click()
	if PlateEmp.Transparency == 1 then
		PlateEmp.Transparency = 0
		Plate1.Transparency = 1
		Plate2.Transparency = 1
		Plate3.Transparency = 1
	end
wait (2) 
function click()
	if PlateEmp.Transparency == 0 then
		PlateEmp.Transparency = 1
		Plate1.Transparency = 0
		Plate2.Transparency = 1
		Plate3.Transparency = 1
	end
end

script.Parent.ClickDetector.MouseClick:Connect(click)

This script only contains the changing of 2 union's transparency. This script is unfinished.

When I test the game, I click the brick with the Click Detector and "PlateEmp" transparency becomes 0, just as I wanted. But then, it turns invisible and "Plate1" becomes 'un-invisible' or transparency is equal to 0 without me clicking the brick again. What am I doing wrong?

If it helps, I am trying to make a script similar to that of the food in Minnie's Diner in "Clear Skies Over Milwaukee" by Toast22A.

If you are answering, I don't mean to sound rude but can you be specific about the code or actions I need to take because I am fairly new to scripting and this is my first 'partially' working script.

1 answer

✓ Accepted answer

So, You put 2 functions with wait(), so, the script runs both of them, and as you put if there, it's good, but when it becomes invisible, the other fuction could run.

I am sorry if you couldn't understand my explanation.

Basically, you need to put the Ifs into 1 function, I will leave the script below.

local ClickHere = script.Parent.Parent.ClickHere
local PlateEmp = script.Parent.Parent.PlateEmp
local PlateInv = script.Parent.Parent.PlateInv
local Plate1 = script.Parent.Parent.Plate1
local Plate2 = script.Parent.Parent.Plate2
local Plate3 = script.Parent.Parent.Plate3

function click()
    if PlateEmp.Transparency == 1 then --If invisible
	    PlateEmp.Transparency = 0
        Plate1.Transparency = 1
        Plate2.Transparency = 1
        Plate3.Transparency = 1
    elseif PlateEmp.Transparency == 0 then --If visible
	    PlateEmp.Transparency = 1
        Plate1.Transparency = 0
        Plate2.Transparency = 1
        Plate3.Transparency = 1
    end
    wait(2) --Cooldown between clicks, I think that's what you wanted earlier.
end

script.Parent.ClickDetector.MouseClick:Connect(click)

Sorry if you couldn't understand my explanation again, I am not good at explaining.

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