✓ Accepted answer
Sort of...
This method would involve DataStores.
Basically you'd have two spawns in the same position. Name one of them LoadData and the other SpawnPoint [the spawnpoint would spawn normal users on it...]
Now you'd have to make this spawnpoint named LoadData [from now on it's just "the spawnpoint"] inactive so people don't autospawn on it. Do this in its properties.
Now view this example from the Roblox Wiki
local TeleportService = game:GetService("TeleportService")
local level1Id = 408502340
local level2Id = 408502380
local level1SpawnName = “LoadData"
local player = -- your method of finding the player.
if player then TeleportService:TeleportToSpawnByName(level1Id , level2SpawnName, player)
end
end
script.Parent.Touched:connect(onTouched)
You'd then want to include some DataStore code, doing the following:
- Updating somewhere in the Datastore to store some info, maybe a table of numbers[that would translate into different functions in the main code, the code below would print the first value and you can convert that into whatever you want:
print(yourTable[1])
- Writing a Getasync script for when a player is added [I'm not sure how you'd detect whether the player had come from another game] to find these tables as I said and then running a function to translate them into different things.
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local function onPlayerAdded(player)
local scope = player.UserId
local loadData = DataStoreService:GetDataStore("LoadData")
pcall(function()
loadData:GetAsync(scope)
end)
end
Players.PlayerAdded:Connect(onPlayerAdded)
- Writing a SetAsync script to override the string in the datastore thus resetting it and making a clean area for more code:
local DataStoreService = game:GetService("DataStoreService")
local playerStats = DataStoreService:GetDataStore("LoadData")
local scope = player.UserId
pcall(function()
loadData:SetAsync(scope, nill)
end)
This all should work, but keep in mind the following:
ALWAYS pcall() DataStore updating/reading functions. If these fail, any code after them won't run. A pcall won't come accross this hurdle
If creating remoteevents to update DataStores, make sure you protect them somehow against exploiters. This is the same if you make one for TeleportService, another exploiter favourite.
All of this code is open-sourced and mostly pulled from the Roblox Wiki. I edited it for your needs, just set your player finder to the variable "player" and have basic understanding on how these work.
If you need any help, contact me on ROBLOX. Any errors, contact me also [if you can't solve them that is.] I also have a discord, and I'm in the scripting helpers channel. I'm Reece#8897 if you need me.