Log in to vote

How would I make a Tycoon Saving Progress and Money? [closed]

Asked by
SynnDC 8
12 days ago

So I'm making a tycoon game with a bit of scripting experience. I do get that you can use Data Store but I really don't get it. It could be awesome if someone helped me out a bit. I'm using Zednov's Tycoon Kit for this tycoon game. If you need the scripts, just ask me please.

Closed as Not Constructive by 2_MMZ, opgeeza, and Kiriot22

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

1 answer

Log in to vote
Answered by
MattVSNNL 116
12 days ago
Edited 12 days ago

If you use this code, You gotta try it in a real game

Add a script to server script service and call it dataHandler or whatever you want

Here's the code you use:

-- Adding variables like the data store service, myData store is your data store, Players left is to detect if there's amount of players to detect when the server can shutdown
local dataStoreService = game:GetService("DataStoreService")
local myDataStore = dataStoreService:GetDataStore("RobloxDataStore")
local playersLeft = 0


    -- every time a player joins it add 1 more to the players left

    playersLeft = playersLeft + 1

    -- Adding money to the play
    local leaderstats ="Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local money ="IntValue")
    money.Name = "Money"
    money.Value = 0
    money.Parent = leaderstats

    -- This adds data into the player data with userid

    local PlayerUserId = player.UserId

    -- Making a blank variable to store data

    local player_data

    -- Checks if it's successful or else you get an error message
    -- Makes a pcall so if there's an error it won't break the script

    local success, errorMessage = pcall(function()

        -- Sets player_data as players userid in your datastore

        player_data = myDataStore:GetAsync(PlayerUserId)

    -- If it's successful then the money will be what we saved

    if success then
        money.Value = player_data.Money

-- Makes a bindable event, Used to tell the script to do something when the game is shutting down

local bindableEvent ="BindableEvent")

-- Fires what a player leaves the game


    -- Gets the userid again

    local playerUserId = player.UserId

    -- The player_data you can save money is your money value

    local player_data = {
        Money = player.leaderstats.Money.Value

    -- When a player leaves it will set your money to money in player data at the amount of money you have

    local success, errorMessage = pcall(function()
        myDataStore:SetAsync(playerUserId, player_data)

        -- Removes from players left

        playersLeft = playersLeft - 1

        -- Fires the bindable event


    -- If it was successful then it prints saved to tell you that it was successful else it tells you what the problem is

    if success then

-- If the players left is above 0 then the server is gonna wait until everyone's data was saved and then it can shut down

if playersLeft > 0 then

please read what I put the green things in, I tell you how it works

All right, I will try it out and see if it works. Thank you so much. SynnDC 8 — 9d
So, I tried it out and all it does is make a new leaderstat from the one I already have. SynnDC 8 — 9d
please read what I put the green things in, I tell you how it works MattVSNNL 116 — 9d
Yes I did that but is there any way I can make it save money and save the tycoon? Not just adding a different value to the leaderboard. SynnDC 8 — 7d
If you want to save the tycoon, that would require saving a model to the datastore,,, i found this link, but it looks complicated: . I am no expert but if you are making a regular tycoon where the player has to buy stuff and add it, maybe you can save what the player has bought so when they rejoin it has the info Omq_ItzJasmin 504 — 5d