Button Disappearing Script

I am trying to make a tycoon and this script to make a button appear when another button disappears. This is my script.

local button = script.Parent

local otherbutton = workspace.DoorWallMaker.Spawner.Transparency

button.Transparency = 1

wait(1)

while true do

	if otherbutton == 1 then
		print("e")
		button.Transparency = 0
		wait(0.05)
	else
		print("no")
		wait(0.05)
	end
	
end

This seems like it should work. Why is it not working?

1 Like

Are there any errors in output?

No, it just spams “no” just like I programmed it to

Is there supposed to be a value inside of Spawner? because in the if statement you’re comparing an instance to a number

@JollyGameCrazy is right. Also, I recommend you create a function and store your information in that instead. Then call it every time other button’s properties change using otherbutton.Changed. This is more reliable than a while loop.

1 Like

I think you meant this

if otherbutton.Transparency == 0

But yeah once you get that out I think you fixed everything in there.

1 Like

I apologize to everyone, I made a typo and have now edited the post. However, it still doesn’t work.

Try using a function like I mention. This may fix your problem and is certainly a better method. Btw, is your script local?

No. I will try to figure out how to use a function for that purpose. Thanks!

Create your function an d place your if statements in there. Then call it using otherbutton.Changed:Connect(functionname).

1 Like

Hmm, strange. However, maybe its because the other button isn’t at 1 to begin with. When you start the game, nothing is changing the otherbutton’s value. try @Fledgeon’s method and do this


otherbutton.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
otherbutton.Transparency = 1 
end
-- keep the while true do script but put the function before the while true do
end)