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

My play button won't fade with my code below. Why won't it work?

I'm trying to make my play button fade out every time I click it, but it just won't fade. Here is the code I typed:

local DBO = script.Parent
local PB = script.Parent.PlayButton
local BG = script.Parent.Background

function onClick(MouseButton1Click)
	if PB.MouseButton1Click == true then
		for i = 0, 1, 0.1 do
			PB.BackgroundTransparency = i
		end
	end
end
script.Parent.PlayButton.MouseButton1Click:connect(onClick)

I can't figure out why this code won't work.

3 comments

0

remove "if PB.MouseButton1Click == true then" and an "end"

0

And you didn't add a wait in your for loop, so when it gets there, it'll set the transparency to 1 so quick that it wont give off a "fade" effect.

0

thanks it worked!!

2 answers

✓ Accepted answer

You used an unnecessary if statement inside the function. Take this out and it ill work functionally.

Your code would look like this:

local DBO = script.Parent
local PB = DBO:WaitForChild('PlayButton') -- Use WaitForChild to make sure that the object is actually there before you use it or it will show up as a nil variable
local BG = DBOWaitForChild('Background') 

function onClick() -- You didn't need anything to take place as a variable in this function
	for i = 0,1,0.1 do
		PB.BackgroundTransparency = i
		wait()
	end
end

PB.MouseButton1Click:connect(onClick)

If I helped please accept this answer...

You tried to reference PB.MouseButton1Click, which is event that is fired when the mouse is clicked. Obviously, you can't check if an event type is true or false, so either the code simply doesn't work or the game errors out.

Removing the MouseButton1Click check should fix it.

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