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 7 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:

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.

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

2 answers

Log in to vote
2
Answered by
RGRage 45
7 years ago
Edited 7 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:

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

Ad
Log in to vote
0
Answered by 7 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