How would I make a black screen that fades on and off when a player goes through a teleporter

I am trying to create a black screen that fades onto the players screen when they touch the teleport block and then once they have been teleported for the black screen to fade off the players screen


I don’t know if I should implement it into this script or do it separate but this is the script that teleports the player when they touch the teleporter

The main issue is that i dont know how to define the player from them touching the block

I have tried looking about on the dev forum but cant really find anything that related to this specifically

any assistance would be appreciated

5 Likes

you can fire the client and make a tween for the background transparency of a black frame that’s size is {1,0,1,0}

2 Likes

would you be able to show me an example on how to do that cos I’ve never really worked with remote events properly

3 Likes
--client
local remote = --path here

remote.OnClientEvent:Connect(tween)

--server

local remote = --path here
remote:FireClient(specified_player)

ps: no need to tp on the server btw save recourses and do it on the client

1 Like

I am pretty sure that this is way easier

local fade = -- Frame name
local function FadeIn()
	fade.Visible = true -- (you can also just set the BackgroundTransparency to 1 so you don't have to make the frame visible)

	for i = 1, 0, -0.03 do
		fade.BackgroundTransparency = i
		wait(.01)
	end
end

local function FadeOut()

	for i = 1, 0, 0.03 do
		fade.BackgroundTransparency = i
		wait(.01)
	end
end

EnterTeleportationPart.Touched:Connect(FadeIn)
EnterTeleportationPart.TouchEnded:Connect(FadeOut)

but how would I create the black screen inside the players gui first

Go into StarterGui, add a ScreenGui (name it if you want), put in a frame and a local script and paste the script there (change variables if needed)

Size the frame to 1, 0, 1, 0
Make the BackgroundColor Black
Set BackgroundTransparency to 1
And if you notice a weird thing if the frame is not fully on screen and cuts of at the top, go to the ScreenGui and IgnoreGuilnset (this only happens in game)

also for the localscript make a variable for the part that gets touched, I forgot that

1 Like

add a script inside the part

script:

script.Parent.Touched:Connect(function(hit)
if hit and hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local gui = Instance.new("ScreenGui", player.PlayerGui)
gui.Name = "TeleportingBlackFade"
gui.IgnoreGuiInset = true
local black = Instance.new("Frame", gui)
black.Name = "Black"
black.BackgroundTransparency = 1
black.BackgroundColor = Color3.fromRGB(0, 0, 0)
black.Size = Udim2.new(1, 0, 1, 0)
local ts = game:GetService("TweenService")
local tween1 = ts:Create(black, TweenInfo.new(1, Enum.EasingStyle.Linear), {BackgroundTransparency = 0})
local tween2 = ts:Create(black, TweenInfo.new(1, Enum.EasingStyle.Linear), {BackgroundTransparency = 1})
tween1:Play()
tween1.Completed:Connect(function()
hit.Parent.HumanoidRootPart.CFrame = workspace.door2.CFrame + workspace.door2.CFrame.LookVector * 5
task.wait(1)
tween2:Play()
end)

tween2.Completed:Connect(function()
gui:Destroy()
end)
end
end)

Instead of using a frame, use ColorCorrectionEffect in Lightning and just tween its contrast to -1 and then back to 0.1.

Here is an example.

--Black Transition:

local FadeInfo = TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)

local Goal = {Brightness = -1,Contrast = -1}
local Tween = TweenService:Create(ColorCorrectionEffect , FadeInfo, Goal)
Tween:Play()

--Reseting:

local Goal = {Brightness = 0.1,Contrast = 0.1} 
local Tween = TweenService:Create(ColorCorrectionEffect , FadeInfo, Goal) 
Tween:Play()

You could use tween service to tween the transparency of a black frame like this:

local frame = game.StarterGui.Frame -- Enter the name of the frame
local door = script.Parent

local tweenService = game:GetService("TweenService") -- tweenService

local appearInfo = tweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false) -- TweenInfo
local disappearInfo = tweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false)

local appear = tweenService:Create(frame, appearInfo, {Transparency = 0})
local disappear = tweenService:Create(frame, disappearInfo, {Transparency = 1}

door.Touched:Connect(function(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    if humanoid then
       appear:Play()
       wait(2)
       disappear:Play()
   end
end)
door = script.Parent

door.Touched:connect(function(hit)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	if humanoid then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		local screen = game.ServerStorage.Gui.Fade1:Clone()
		screen.Parent = player.PlayerGui
		for i = 1, 0, -0.3 do
			screen.Fade.BackgroundTransparency = i
			wait(.01)
		end
		
		wait(.5)
		local plrCFrame = hit.Parent.HumanoidRootPart.CFrame
		hit.Parent.HumanoidRootPart.CFrame = workspace.teleport.door1.CFrame + workspace.teleport.door1.CFrame.LookVector * 5
		for i = 0, 0, 0.3 do
			screen.Fade.BackgroundTransparency = i
			wait(.01)
			screen:Destroy()
		end
	end
		
		
	end)

I managed to do it by doing this, not sure if it would’ve been easier another way or whatever but this is what I found to work

frames are not visible if it is not a descendant of ScreenGui

Oh yeah, I forgot to add that.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.