How to Create a Roblox Tycoon (Part 5: Saving Player Data)

Up until now, players could buy buttons, unlock droppers, and earn cash. But when they left the game, all progress was lost. In this part, we’ll add data saving and loading using ProfileService so players keep their cash and unlocked items.


Step 1: Install ProfileService

  1. Open the Toolbox.
  2. Use the link (provided in video/description) to get the official ProfileService module.
  3. Insert it into your game.
  4. Drag ProfileService into your Data Script inside ServerScriptService.

Step 2: Create a Data Template

This defines what each player’s save file will look like.

-- DataScript

local ProfileService = require(script:WaitForChild("ProfileService"))

-- Default template for new players
local ProfileTemplate = {
    Cash = 0,
    Items = {} -- list of purchased item IDs
}

If you later add more features (pets, badges, etc.), just extend this template. Old players’ profiles will update automatically using .Reconcile().


Step 3: Set Up a Profile Store

We need a “database” (called a ProfileStore) to keep player saves.

local ProfileStore = ProfileService.GetProfileStore("PlayerData", ProfileTemplate)

-- Active profiles in this session
local Profiles = {}

Step 4: Load Player Data on Join

We’ll fetch or create the player’s save file when they join.

local function PlayerAdded(player)
    local profile = ProfileStore:LoadProfileAsync("Player_" .. player.UserId)

    if profile then
        profile:AddUserId(player.UserId) -- GDPR compliance
        profile:Reconcile()              -- fill missing values
        profile:ListenToRelease(function()
            Profiles[player] = nil
            player:Kick("Data issue. Please rejoin.")
        end)

        if player:IsDescendantOf(game.Players) then
            Profiles[player] = profile
        else
            profile:Release()
        end
    else
        player:Kick("Unable to load your data. Please try again.")
    end
end

game.Players.PlayerAdded:Connect(PlayerAdded)

-- Handle players already in-game when script starts
for _, plr in ipairs(game.Players:GetPlayers()) do
    task.spawn(PlayerAdded, plr)
end

-- Release profile when player leaves
game.Players.PlayerRemoving:Connect(function(player)
    local profile = Profiles[player]
    if profile then
        profile:Release()
    end
end)

Step 5: Connect Data to Leaderstats (Cash)

We’ll link the saved Cash value to the player’s visible leaderstats.

-- Inside PlayerAdded after loading profile

-- Create leaderstats
local folder = Instance.new("Folder")
folder.Name = "leaderstats"
folder.Parent = player

local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Value = profile.Data.Cash or 0
cash.Parent = folder

-- Save cash whenever it changes
cash:GetPropertyChangedSignal("Value"):Connect(function()
    profile.Data.Cash = cash.Value
end)

Step 6: Save Purchased Items

Whenever a player buys an item, we’ll store its ID in their data.

  1. In DataScript, add a BindableEvent: ItemUnlocked
  2. Listen for it:
local ItemUnlocked = Instance.new("BindableEvent")
ItemUnlocked.Name = "ItemUnlocked"
ItemUnlocked.Parent = script

ItemUnlocked.Event:Connect(function(player, itemId)
    local profile = Profiles[player]
    if profile then
        table.insert(profile.Data.Items, itemId)
    end
end)
  1. In PlotHandler, after confirming purchase, fire the event:
game.ServerScriptService.Data.ItemUnlocked:Fire(player, button:GetAttribute("ItemId"))

Step 7: Load Purchased Items

When a player rejoins, we rebuild their Tycoon from the saved item IDs.

local function LoadItems(player, itemIDs)
    local plot = GetPlayerPlot(player) -- custom function from earlier
    for _, id in ipairs(itemIDs) do
        local templateItem = GetItemFromTemplatePlot(id) -- helper function
        if templateItem then
            local clone = templateItem:Clone()
            clone.Parent = plot.Items
            -- Positioning logic here
        end
    end
end

Make sure to skip loading buttons for items they already own:

if table.find(itemIDs, button:GetAttribute("ItemToUnlock")) then
    continue
end

Step 8: Test Data Saving

  1. Go to Home → Game Settings → Security.
  2. Enable API Services.
  3. Play in Server Mode.
  4. Earn cash, buy items, then leave and rejoin.
  5. Your progress should reload!

Recap

  • Installed ProfileService.
  • Created a data template for Cash + Items.
  • Saved and loaded player profiles with LoadProfileAsync.
  • Hooked up leaderstats for live Cash display.
  • Stored item IDs when purchased.
  • Reloaded purchased items on join.

Next Step

Your Tycoon now saves and loads progress! In the next part, we’ll polish the gameplay — adding UI, upgrades, and polishing mechanics to make it feel like a real Roblox Tycoon.