(HELP) Rejoin Previous Game System

Hello everyone,
I am working on a story game now and I am trying to make a system where if you get kicked or leave and want to rejoin your previous game you have the ability to.


This ui will be in the lobby and it will pop up if you started a round and left. How will I go about finding the round once you join?

2 Likes

thanks for the help in advance.

4 Likes

Once someone created a round you keep the reference to that round (let it be an id or whatever). Once the game detects the player disconnecting it saves the reference of the round, along with everything necessary to load the round again, and saves it to the game’s datastore.
Once the player joins again, the game will check if the player has an entry in the datastore and load everything that has been saved in it.

Example:

-- pseudo code
local Datastore = game:GetDatastore("YourDataStore")

local player = game.Players:GetCurrentPlayer()

-- when a player leaves the game:
player.Disconnecting:Connect(function()

    -- saving the current game state to the datastore
    -- reference is the player's userId
    -- the data (the table) is everything that is required to load a round
    Datastore:SetAsync(player.UserId, {
        ["RoundID"] = getRoundId(),
        ["PlayerGold"] = player.stats.Gold.Value,
        ["PlayerHealth"] = player.stats.Health.Value,
        ["PlayerWeapons"] = player.backpack:GetChildren()
    })
end)

-- when a player joins the game
player.Connecting:Connect(function()
    local data = Datastore:GetAsync(player.UserId)

    if (data ~= nil) then
        -- there has been data saved to the datastore
        -- create or resume the round with the given data
        
        -- remove the entry from the datastore
        Datastore:RemoveAsync(player.UserId)
    end
end)

Here is some documentation for ROBLOX’s DataStoreService.

If you have questions please let me know.

  • DosenSuppe2_0
1 Like

Why are you saving player gold, health and weapons inside the datastore? You can just save it in a table since it doesn’t need to save between servers

3 Likes

You can’t save tools in the Datastore.You should save their names or values instead of saving tools.Because datastore is only a service that stores values.

2 Likes

OP said “Disconnects or gets kicked” indicating that the user has left the server. This is either by being send back into a lobby-server or by leaving the game, either way, the user won’t be in the same server.

The only way to store a user’s data is using the DatastoreService as it’s uncertain whether they’ll be assigned the same server as before when rejoining the game. It’s also unclear whether the server is still open or has been closed. Using the DataStoreSerivce gives you extra protection against data-loss.

4 Likes

It’s pseudo code as indicated by the first line. It would be up to him how he implements a tool to value converter/ reference.

2 Likes

He says “when reconnecting to the previous server”,

He’s already trying to make the user reconnect to the previous server, if they don’t the data won’t be saved

2 Likes

Player disconnects from game/ server → Player joins game again → Game sees there is an open round to that player → Game asks player to resume the round

This is what he describes.
OP said, and I quote the exact words: “if you get kicked or leave”, indicating the player leaving or changing the server or game. Thus he only way to reliably store data is to use the DataStoreService. It’s uncertain whether a player was the last one in a server, making it close automatically when they leave. Once the server is closed you won’t able to join the exact same server again and all data in that server is lost.

4 Likes

what is the point of saving it if its closed? I am assuming your items, health, gold etc is temporary to only that game/round. So if the server is closed, it means you guys lost the round and need to start over, so I feel like saving is pointless

1 Like

He said that he is working on a “story game”. Rather than having to play the story over and over again after every time you leave, all the data gets loaded from where you ended. That’s pretty normal for games to do, even outside of Roblox.

Examples are:

  • Minecraft
  • Fortnite
  • Portal
  • or really any other game with a story or data that needs to be saved.

Their advantage is that they can save the data on the user’s PC directly. But we, roblox developer, do not have that privilege so we have to use the DataStore to save the data for the users instead.

1 Like

Is anybody able to solve this? I might close the post or start a new one.

Upon joining a round you can set a variable in the player’s datastore profile which holds the round’s server’s JobId. Then upon rejoining the main game, it checks if the JobId is in the player’s datastore profile and checks if the server is still up. If the server is still up, it prompts the player to rejoin. If not, it clears the unique id from the player’s datastore profile. If they click yes, it uses TeleportService:TeleportToPlaceInstance(PlaceId, JobId, Player) to teleport the player back to the server.

And with the round system, if you want the player’s progress to still be there upon rejoining, you could just cache it, assuming that there isn’t much data and server uptime is relatively short.

1 Like