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

Why won't my frame transparency script work?

The purpose of this script is to make the screen fade into black when a button is clicked. For some reason this does not happen and it confuses me. Could you please explain what I did wrong and how I could fix it?

function OnClicked()
  local x =  Instance.new("Frame")
	x.Parent = script.Parent.Parent.ScreenGui
	x.BackgroundColor3 = Color3.new(0,0,0)
	x.Size = {1, 0},{1, 0}
	for i = 0 , 1, .1 do
    x.BackgroundTransparency = i
    wait(0.2)
end

	x.Destroy = true
	
end

script.Parent.MouseButton1Down:connect(OnClicked)



3 comments

0

Wait, the frame needs to be clicked? or another button like a Text Button?

0

Another button but I fixed it

0

Ok

3 answers

✓ Accepted answer

You need to use BackgroundTransparency not Transparency

example

x.BackgroundTransparency = 0.1

and you also need to change

x = script.Parent.Parent.ScreenGui

to

x.Parent = script.Parent.Parent.ScreenGui

i also recommend using a loop rather than writing the same thing 10 times

example

for i = 0 , 1, .1 do
	x.BackgroundTransparency = i
	wait()
end

your size is wrong you would need to type

x.Size = UDim2.new(xScale, xOffset, yScale, yOffset)

8 comments

0

Still doesn't work

0

Let me try

0

Still does not work

0

size is wrong

0

use what i just put above

0

oh ok

0

I FIXED IT! THANK YOU SO MUCH BOTH OF YOU GUYS HOW CAN I THUMBS UP BOTH!

0

click the up arrows to thumbs up and your welcome

Your problem is that you are trying to change the transparency, when the value you want to change is BackgroundTransparency. Additionally, your code is very inefficient; you can replace that long reduntant piece of code with a loop.

the best loop to use here is a for loop, because they take little effort to make and are most commonly used when you want a counting variable

function OnClicked()
  local x =  Instance.new("Frame")
    x = script.Parent.Parent.ScreenGui
    x.BackgroundColor3 = Color3.new(0,0,0)
    x.Size = UDim2.new(1,0,1,0)
 	for i = 0, 1, .1 do
		x.BackgroundTransparency = i
		wait(0.2)
	end
	x:Destroy()
end

script.Parent.MouseButton1Down:connect(OnClicked)

The first parameter of a for loop is the variable you want to count, with the starting value. In this case, "i" is our counting variable, and we want it to start counting up from 0.

The second parameter is the goal you want to reach. The for loop will continuously run the given code until the counting variable reaches that goal.

The third parameter is the increment at which the counting variable counts at. The increment is added to the counting variable with each iteration of the for loop.

For more information on loops, you can search the roblox wiki here, or the scripting helpers glossary here.

6 comments

0

Hmm it still does not work.

0

are you getting any errors?

0

let me see

0

ScreenGui is not a valid member of Frame 13:28:32.598 - Script 'Players.Player1.PlayerGui.ScreenGui.Frame.Play!.LocalScript', Line 3 13:28:32.598 - Stack End

0

You're not referencing your GUI correctly. Make sure that x is equal to the right value. There doesn't appear to be any screengui in the frame the script is referring to.

0

Ok

Ok so I combined what both of you guys said and I fixed everything.

function OnClicked()
  local x =  Instance.new("Frame")
    x.Parent = script.Parent.Parent.Parent
    x.BackgroundColor3 = Color3.new(0,0,0)
    x.Size = UDim2.new(1, 0, 1, 0)
	for i = 0, 1, .1 do
        x.BackgroundTransparency = i
        wait(0.2)
    end
end

script.Parent.MouseButton1Down:connect(OnClicked)

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