So I am working on developing a teleport system for a game I dev for. The teleport system would transfer players between games along with their vehicle too.
I know that I can use DataStores to send the data needed for what vehicle they were in and what configuration it had, but I am not too sure if I can make the other game detect if a player was brought in from a different game or not. Is this possible?
To be clear, are you teleporting between two places within one game, or two separate games each accessible from their own game page?
So the player can access the second game either by joining it from the game page, or by teleporting to it from the first game, and you need to detect which of these happened, correct?
If you need something to happen in the new place only if the player gets there in a certain way I would do the following:
Before the player gets teleported, set some value in their datastore to true. When they arrive in the new place, check if that value is true, if yes, you know that they got there by being teleported. After that set the value to false again.
You could also set this value to a certain number depending on where you teleport then from, that way, you could detect exactly what place they were teleported from. Although you may not need that.
You can use TeleportOptions to set the teleport data like this:
local teleportOptions = Instance.new("TeleportOptions")
teleportOptions:SetTeleportData({["VehicleName"] = playerVehicle}) -- Change playerVehicle to the current vehicle of player you are teleporting
When using TeleportService:TeleportAsync(), you need to pass TeleportOptions as the third parameter.
For getting the value when player was teleported, you can do this:
Players.PlayerAdded:Connect(function(player)
local VehicleName = player:GetJoinData().TeleportData["VehicleName"]
if VehicleName then -- VehicleName was set, means player was TELEPORTED
print(player.Name.." was teleported with "..VehicleName)
end
end)