So, I have a function that fires when you come from a Teleportation from one place of my game, and it’s supposed to show a GUI. I tried the StarterPlayingScripts, putting it in the concerned GUI, but nothing.
Anyways of fixing this?
Here’s my code by the way:
local TPS = game:GetService("TeleportService")
function onArrival(player)
print("Teleported Player is here!")
end
TPS.LocalPlayerArrivedFromTeleport:Connect(onArrival)
Just a hypothesis, maybe the event is firing before the LocalScript starts running.
Have you tried putting it inside ReplicatedFirst? That’s where the first LocalScripts can run.
As @return_end1 says and as stated from the Roblox Developer Hub:
This event should be connected immediately in a LocalScript parented to ReplicatedFirst . Otherwise, when the connection is made the event may have already fired.
Also, the parameters you have included are not what is actually sent. The two parameters that are sent is the custom loading screen instance and data you sent while teleporting the player (if you sent data, of course)
Here’s an implementation in ReplicatedFirst that should work for you:
local RF = game:GetService("ReplicatedFirst")
local Player = game:GetService("Players").LocalPlayer
local TPS = game:GetService("TeleportService")
TPS.LocalPlayerArrivedFromTeleport:Connect(function(loadingScreen, teleportData)
-- if you have a custom loading screen from the game you teleport the player from, it will appear here
if loadingScreen then
-- do whatever
wait(5)
-- if you didn't have a custom loading screen from the last place,
-- you can add in a loadingScreen
elseif not loadingScreen then
loadingScreen = -- you loading screen here
loadingScreen = loadingScreen:Clone()
loadingScreen.Parent = Player:WaitForChild("PlayerGui")
-- do whatever here
wait(5)
end
loadingScreen:Destroy()
end)