How would i make a fading screen function?

I want to make a fading screen gui during teleporting a player.

7 Likes

Try:

local frame = script.Parent; -- Change this to your fading gui object

-- Fade In
repeat
    frame.BackgroundTransparency = frame.BackgroundTransparency - 0.05;
    wait(0.05);
until frame.BackgroundTransparency <= 0;

-- Fade Out
repeat
    frame.BackgroundTransparency = frame.BackgroundTransparency + 0.05;
    wait(0.05);
until frame.BackgroundTransparency >= 1;
10 Likes

I putted this in my main script in serverscript service but it would not work.

`local frame = game.StarterGui.ScreenGui.TextLabel`
    local function StartRound()
    repeat
        frame.BackgroundTransparency = frame.BackgroundTransparency - 0.05;
        wait(0.05);
    until frame.BackgroundTransparency <= 0;

    -- Fade Out
    repeat
        frame.BackgroundTransparency = frame.BackgroundTransparency + 0.05;
        wait(0.05);
    until frame.BackgroundTransparency >= 1;
    end
1 Like

Do you want it to remove the current roblox loading screen?

1 Like

Your error is that you’re attempting to change the StarterGui, players have GUIs in their PlayerGui.

local PlayerGui = game.Players.LocalPlayer.PlayerGui

Try change the script for this to a LocalScript in the frame and use

local TeleportScreen = game:GetService("TeleportService"):SetTeleportGui(script.Parent)

If you make it so the frame fades in, set the teleportscreen to the frame, then do the teleport, then once they arrive, fade out a similar frame, that should get the desired effect.

3 Likes

This code needs to be on the client in a LocalScript to work, preferably in StarterGui as you are modifying gui’s. Anything on the server, e.g:ServerScriptService, needs to be in a script to work.

I am not sure how your system is set up so I have a made a little fix to the top line of your code as the way you had it before wasn’t the correct way to find a gui object in a player.

local frame = script.Parent -- Change this to the location of the frame
local function StartRound()
    repeat
        frame.BackgroundTransparency = frame.BackgroundTransparency - 0.05;
        wait(0.05);
    until frame.BackgroundTransparency <= 0;

    -- Fade Out
    repeat
        frame.BackgroundTransparency = frame.BackgroundTransparency + 0.05;
        wait(0.05);
    until frame.BackgroundTransparency >= 1;
end
2 Likes

This does not work because its not in my start round function in my main script so it just does not run when i want it to.

1 Like

You’ll probably want something like this, haven’t tested but it will initiate a teleport along with a fading frame, to ‘unfade’ in the other place you’ll need to use GetArrivingTeleportGui.

game:GetService("ReplicatedFirst"):RemoveDefaultLoadingScreen()
local LocalPlayer = game:GetService("Players").LocalPlayer
local ScreenGui = script.Parent
local Frame = ScreenGui.Frame
local fadeDuration = 1
local placeId = 0

Frame.BackgroundTransparency = 1

-- Set Teleport Gui
local TeleportScreen = game:GetService("TeleportService"):SetTeleportGui(ScreenGui)

-- Tweening Properties for Frame
local tweenInfo = TweenInfo.new(fadeDuration, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)

-- Teleport function
game:GetService("TeleportService"):Teleport(placeId, LocalPlayer, nil, TeleportScreen)

-- Create the tween frame
game:GetService("TweenService"):Create(Frame, tweenInfo, {BackgroundTransparency = 0}):Play()
6 Likes

Or if you want another alternative:

 for i = 0,1,.1 do -- each .05 seconds this increases transparency by .1 until it reaches 1
      frame.Transparency = i -- sets transparency to current i
      wait(.05) -- customize wait as you wish
 end
2 Likes

That’s fine but TweenService is much more robust and gives you more options in stylizing the fade animations for this particular function.

Erm, OP, the Scripting Support category is not for asking for free code. You should not be posting a thread unless you have tried making this yourself and have searched the forums or developer hub for help.

There are already many code samples available around to help out with finding an answer. For fading, you can look at tweens. For configuring a teleport Gui, there is SetTeleportGui.

1 Like

How do I make it all happen at once, Instead of it fading one by one?

You could Tween the Frames transparency like this:

local TweenService = game:GetService(“TweenService”)
local FadeSpeed = 1
local tween = TweenService:Create(script.Parent.Frame, TweenInfo.new(FadeSpeed), {Transparency = 1})

4 Likes