How can I make a transition when a player tries to teleport to another part of a place?

I am trying to make a game that has buildings that you teleport to (fake exterior), and when you go to the door to teleport to them you have a transition that is basically a fade in to black and then the black fades out. I tried to use a server-client based RemoteEvent, but it seems to have absolutely no effect even though I know it is being fired (and unusually it is also fired when the server first starts.) Can somebody help me out with this?

My server-script:

-- Teleport function --
	

for i, doorTouched in pairs(Server.teleportDoor:GetDescendants()) do
	if doorTouched:IsA("Part") then
		doorTouched.Touched:Connect(function(plr)
			local hp = plr.Parent:FindFirstChild("HumanoidRootPart")
			if hp then
			local localplr = game.Players:GetPlayerFromCharacter(plr.Parent)
			Server.remoteEvent:FindFirstChild("teleTrans"):FireClient(localplr) -- This is supposed to trigger a transition, but it has no effect.
			hp.CFrame = CFrame.new(doorTouched.Config.Location.Value)
			end
		end)
	end
end

Here is my localscript which handles the transition too:

-- Teleportation Handler --

local function transStart(Gui)
	local transition = Gui:FindFirstChild("TransitionFrame")
	local info = TweenInfo.new(2, Enum.EasingStyle.Quint,Enum.EasingDirection.Out)
	
	local maxTrans = {
		Transparency = 1,
		BackgroundColor3 = Color3.new(1,1,1) 
		}
    local tween = Client.tweenService:Create(transition,info,maxTrans)
	transition.Visible = false
end

local function transMove(player)
	local playerGui = player.PlayerGui
	local transition = playerGui:FindFirstChild("TransitionFrame")
	local info = TweenInfo.new(2, Enum.EasingStyle.Quint,Enum.EasingDirection.In)
	
	local maxTrans = {
		Transparency = 0,
		BackgroundColor3 = Color3.new(1,1,1) 
		}
    local tween = Client.tweenService:Create(transition,info,maxTrans)
	wait(2)
    transStart(playerGui)
end

Client.remoteEvents:FindFirstChild("teleTrans").OnClientEvent:Connect(transMove)
print("received")

I would greatly appreciate the help. Thanks!

2 Likes

The tween won’t play unless you call it.
Add tween:Play() to both functions.

Also, you can use the Tween.Completed event to tell if its finished instead of waiting it out.

tween.Completed:Wait()
1 Like

That would definitely help to start out, lmao. I receive the error:

  13:18:50.012 - Players.stalecars.PlayerGui.ScreenGui.Client :144: attempt to index a nil value
13:18:50.014 - Stack Begin
13:18:50.014 - Script 'Players.stalecars.PlayerGui.ScreenGui.Client ', Line 144 - function transMove
13:18:50.015 - Stack End
local function transMove(player)
	print("received")
	local playerGui = player.PlayerGui -- Line 144
	local transition = playerGui:FindFirstChild("TransitionFrame")
	local info = TweenInfo.new(2, Enum.EasingStyle.Quint,Enum.EasingDirection.In)
	
	local maxTrans = {
		Transparency = 0,
		BackgroundColor3 = Color3.new(1,1,1) 
		}
    local tween = Client.tweenService:Create(transition,info,maxTrans)
	tween:Play()
	tween.Completed:Wait()
    transStart(playerGui)
end

I’m very sure that the localplayer passed on during the remoteevent shouldn’t be nil even though it is printed as nil

It is nil, the first argument in a remoteEvent:FireClient is the receiving player, not the argument that is passed to the function.

Though you could fix this by adding localplr as the second argument as well as the first, I would rather index the player through the client using game:GetService("Players").LocalPlayer

Example:

local LocalPlayer = game:GetService("Players").LocalPlayer

local function transMove()
    local playerGui = LocalPlayer.PlayerGui
    -- The rest.
end

There is no reason to use the player instance that the remote event sent over if you’re in a local script. Use the local player instead.

I changed my code to this:

local function transMove(plr)
	print(Client.localPlayer)
	print("received")
	local playerGui = Client.localPlayer.PlayerGui
	local transition = playerGui.ScreenGui:FindFirstChild("TransitionFrame")
	local info = TweenInfo.new(2, Enum.EasingStyle.Quint,Enum.EasingDirection.In)
	
	local maxTrans = {
		Transparency = 0,
		BackgroundColor3 = Color3.new(1,1,1) 
		}
    local tween = Client.tweenService:Create(transition,info,maxTrans)
    playerGui.ScreenGui.TransitionFrame.Visible = true
	tween:Play()
	tween.Completed:Wait()
    transStart(playerGui.ScreenGui)
end

Nothing is happening however, event is fired but the gui does not become visible or anything.

1 Like

try this lol (Client.LocalPlayer)

…uh Client.localPlayer is in a table I made for all of my variables, I just made localPlayer = game:GetService(“Players”).LocalPlayer

either way that’s not the issue, both print(Client.localPlayer) and print(“received”) do print the correct output

oh ok,my bad

cant you just do ,since its already a variable

 playerGui.TransitionFrame = true

transitionFrame isn’t a property of playergui

it is really,its a vairabel u made

?? I didn’t make that a variable

Can’t you make a custom loading screen for the place that you are going to teleport to? Which will act up like the transition

1 Like

I did that before but it was very inefficient and it sometimes didn’t show while othertimes shown after the player has already teleported

Oh wait sorry nevermind, I thought you meant teleport to another game using TeleportService

yeah, I’m just trying to teleport within the game (move them to a different position)

Well it’s really just working with UIs, change and do stuff when the player teleports

It should be BackgroundTransparency for frames, not Transparency

3 Likes