Role system like break in

Hey Everyone,
I am making a role system similar to break in story i almost got it working but the only problem is I dont know much about datastores so when the player gets their tool, medkit for example it does not carry onto the main game after the teleport. Thanks


my bad for the audio btw i forgot to turn the mic off

For this case, I would advice you don’t use DataStoreService. Rather, you can use the TeleportService itself. See, when you teleport between 2 games, you have the option to send information from the original game to the new game.
Therefore, all you need to do is send the role that the player chose in the Lobby to the main game.

You can do this using the TeleportOptions instance, and calling the :SetTeleportData() function.

For example:

local data = {
    ["Role"] = "Adult",
    ["Class"] = "Medic"

local TeleportOptions ="TeleportOptions")

Then, on the main game, you’d use the PlayerAdded function in order to retrieve this data.

    local joinData = plr:GetJoinData()
    local teleportData = joinData.TeleportData
    print(teleportData.Role) -- would print "Adult"

i never thought about it like that let me try that rn

1 Like

Of course. I’ve edited my reply to include an example, have a look.


i was able to edit my lobby script, not finished with the main game script but here is the lobby one

-- Function to determine the player's role based on inventory
local function determinePlayerRole(player)
    -- Check if the player has the medkit tool in their inventory
    local medkit = game.ReplicatedStorage:FindFirstChild("Medkit")
    if medkit and (player.Backpack:FindFirstChild("Medkit") or player.Character:FindFirstChild("Medkit")) then
        print("Medic assigned to player")
        return "Medic" -- Player has the medkit, assign the "Medic" role
        return "Kid" -- Player does not have the medkit, default to "Kid" role

-- Connect an event to handle role assignment and teleportation
    local roleName = determinePlayerRole(player)

    -- If the role is "Medic," give the player the medkit tool in the lobby
    if roleName == "Medic" then
        local medkitTool = game.ReplicatedStorage:FindFirstChild("Medkit") -- Replace with the actual medkit tool
        if medkitTool then
            medkitTool:Clone().Parent = player.Backpack
            warn("Medkit tool not found in ReplicatedStorage.")

    -- Use TeleportOptions to send role information to the main game
    local teleportService = game:GetService("TeleportService")
    local placeId = 1234567890 -- Replace with the main game's place ID

    local teleportOptions ="TeleportOptions")
    local teleportData = {
        Role = roleName -- Pass the role information

    local success, errorMessage = pcall(function()
        teleportService:Teleport(placeId, player, teleportOptions)
    if not success then
        warn("Teleportation error: " .. errorMessage)

the problem im having now though is that i dont want it to teleport the player i just want it to give the role info

1 Like

I thought you said you needed the role info after the teleport was done?

1 Like

yeah but there is a problem even with the edited script it doesnt carry over to the main game for some reason.

1 Like

Did you give them the item in the main game? Once the player is teleported, you need to have another script in that game that gives them the item after they’ve joined.

1 Like

yeah once the player is teleported the script is supposed to check their role

1 Like

Yeah. I gave you an example of how to do it in my text above. Have you been able to accomplish this?

1 Like