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

Why do I only see this frame in roblox studio but not when I play the game?

Asked by 3 years ago

I'm trying to make a fading blindness effect where a black frame over your screen slowly fades away. The way i'm trying to achieve this is with the background transparency of the frame, the code I have for this is shown here:

inviswall = workspace.Hall.InvisWall
blindness = game.StarterGui.ScreenGui.Blindness

function ShowWall()
    print("Touched")
    inviswallTransparency = 0
    print("Wall visible.")
    wait(5)
    blindness.BackgroundTransparency = 0
    wait(5)
    print("Unblinding.")
    for i = 0, 1, 0.1 do
        blindness.BackgroundTransparency = i
    end
end)

workspace.Hall.InvisTouch.Touched:Connect(ShowWall)

When I play the game the frame doesn't seem to show. When I walk over the part that runs the function I can see the transparency of the frame changing in explorer but nothing changes in the game.

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

It's the same confusion I have when I was starting so I'll explain you

The function of the StarterGui is to copy itself into the Player's Gui when the game loads

So the real Gui is not in StarterGui it is in Player.PlayerGui

First: The gui can only be changed with a local script

Second: The local script has "LocalPlayer" to refers to your player

Create a local script in StarterGui or StarterPlayerScripts and put

inviswall = workspace.Hall.InvisWall
Player = game.Players.LocalPlayer --This is your player
PlayerGui = Player:WaitForChild("PlayerGui") --This is your local Gui I used WaitForChild because the Gui takes time to load
ScreenGui = PlayerGui:WaitForChild("ScreenGui") --Same here
blindness = ScreenGui:WaitForChild("Blindness") --And here


function ShowWall()
    print("Touched")
    inviswallTransparency = 0
    print("Wall visible.")
    wait(5)
    blindness.BackgroundTransparency = 0
    wait(5)
    print("Unblinding.")
    for i = 0, 1, 0.1 do
        blindness.BackgroundTransparency = i
    end
end)

workspace.Hall.InvisTouch.Touched:Connect(ShowWall)

You can also put your local script inside ScreenGui in StarterGui and it will work because the script will also be copied and runned inside the player gui so u can use script.Parent to refer to the ScreenGui and script.Parent.Blindness for the Blindness Frame

Sorry for my english hope you understand me

0
You should also use local variables. nekosiwifi 398 — 3y
0
Yes i use them but i just copied and pasted the script above PepeElToro41 132 — 3y
Ad

Answer this question