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

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

Asked by 8 years ago

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:

01local DBO = script.Parent
02local PB = script.Parent.PlayButton
03local BG = script.Parent.Background
04 
05function onClick(MouseButton1Click)
06    if PB.MouseButton1Click == true then
07        for i = 0, 1, 0.1 do
08            PB.BackgroundTransparency = i
09        end
10    end
11end
12script.Parent.PlayButton.MouseButton1Click:connect(onClick)

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

0
remove "if PB.MouseButton1Click == true then" and an "end" metropolish30 6 — 8y
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. TheeDeathCaster 2368 — 8y
0
thanks it worked!! supercoolboy8804 114 — 8y

2 answers

Log in to vote
2
Answered by
RGRage 45
8 years ago
Edited 8 years ago

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

Your code would look like this:

01local DBO = script.Parent
02local 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
03local BG = DBOWaitForChild('Background')
04 
05function onClick() -- You didn't need anything to take place as a variable in this function
06    for i = 0,1,0.1 do
07        PB.BackgroundTransparency = i
08        wait()
09    end
10end
11 
12PB.MouseButton1Click:connect(onClick)

If I helped please accept this answer...

Ad
Log in to vote
0
Answered by 8 years ago

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.

Answer this question