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