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

Why won't my frame transparency script work?

Asked by 8 years ago

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)



0
Wait, the frame needs to be clicked? or another button like a Text Button? DeveloperSolo 370 — 8y
0
Another button but I fixed it Relampago1204 73 — 8y
0
Ok DeveloperSolo 370 — 8y

3 answers

Log in to vote
1
Answered by 8 years ago

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)
0
Still doesn't work Relampago1204 73 — 8y
0
Let me try Relampago1204 73 — 8y
0
Still does not work Relampago1204 73 — 8y
0
size is wrong ProfessorSev 220 — 8y
View all comments (4 more)
0
use what i just put above ProfessorSev 220 — 8y
0
oh ok Relampago1204 73 — 8y
0
I FIXED IT! THANK YOU SO MUCH BOTH OF YOU GUYS HOW CAN I THUMBS UP BOTH! Relampago1204 73 — 8y
0
click the up arrows to thumbs up and your welcome ProfessorSev 220 — 8y
Ad
Log in to vote
2
Answered by 8 years ago

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.

0
Hmm it still does not work. Relampago1204 73 — 8y
0
are you getting any errors? aquathorn321 858 — 8y
0
let me see Relampago1204 73 — 8y
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 Relampago1204 73 — 8y
View all comments (2 more)
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. aquathorn321 858 — 8y
0
Ok Relampago1204 73 — 8y
Log in to vote
0
Answered by 8 years ago

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)

Answer this question