Data Saving like Billionaire Simulator game

You’re mixing up os.time with tick()

I’m not. tick() used from the client will return time that is relevant to one’s time zone or use an offset from the UNIX Epoch. os.time() means “operating system (os) time” and returns the seconds elapsed since the UNIX Epoch raw.

6 Likes

The examples in this post are very specific.

If you just want to learn how to save data for further use, regardless if it is in a new server, a different one, or the same, you usually want to use DataStores - the ROBLOX wiki has a great explanation and another one with use cases and examples.

In addition to that, if you want to make a daily reward system, here’s an example script from another question:

local DataStore = game:GetService("DataStoreService"):GetDataStore("LastLogin") --Get the DataStore.


game.Players.PlayerAdded:connect(function(Player)
        wait()
    local LastLogin = DataStore:GetAsync(Player.userId)
        if LastLogin then
            local Seconds = os.time()-LastLogin
        local Minutes = Seconds/60
        local Hours = Minutes/60
       print("It has been: "..Hours.." hours Since your last reward") --This just prints how much time has passed since your last reward.
        if Hours >= 24 then
            print("You get a daily login award") --This happens if 24 hours has passed since his last login so he gets an award!
       DataStore:SetAsync(Player.userId,os.time())
        end
    else
       DataStore:SetAsync(Player.userId,os.time())
    end
end)

Source
You might want to read through this to also get a feel on how DataStores work in general.

2 Likes

Interesting, thank you.

A few things to note about this code:

  • You’re loading and saving data regardless of whether or not the player is a guest. This is minor, but worth noting.
  • Don’t call wait() unnecessarily.
  • Don’t save the data when the player joins without a reason.
  • Call the DataStore methods in protected mode, they may error. Do not assume that they won’t error.
2 Likes

Didn’t guest mode get removed? I think there was a public announcement about this…

No, the feature is still there as you can see from the replies, players can still join as guests either accidentally or on purpose until further notice. It’s just not exposed as a public option anymore, but it’s still worth handling in DataStore logic.

2 Likes

This is true but your code won’t run into issues if a guest joins… There is no problem with saving and loading data for guests.

The problem is saving data that is not going to be ever used anymore. You should avoid that.

1 Like

You don’t have to convert UNIX time anymore, just use os.date()

You should just disconnect guests as they are supposed to have been fully removed.

EDIT: Sorry for offtopic

1 Like

Actually, about 10% of users are still given guest mode ability.

1 Like

Let me start off by saying that I don’t think this is that far above this users skill level, he just needs to be set in the right direction.

Now I haven’t read everyone’s post here as I’m on a bit of a time crunch so I apologize if someone already posted what I’m about to.

Lets begin by explaining a few functions. Tick and Os.Time, both of these functions will return how long it’s been since the epoch. For ease we will say a user left the game 30 seconds after the epoch, therefor when we use os.time()/tick it will return 30. (In reality this number is around 1547069000) every second that number will go up, so if they rejoin in 30 seconds then tick/os.time() will return 60.

So how can this help us? Lets say your user is currently making 30,000 dollars per minute. If you save the time that the user rejoins the game and subtract it from the time the user previously left the game it will give you the amount of seconds the user was offline,

Log On - Previous Log off = Offline Time

Now we can simply convert our seconds to minutes and multiply it by how much the user makes. Sorry if this was confusing, as I said I was on a bit of a time crunch!

1 Like

If this was in response to my post, I’ve already stated that I found this to be a misconception. If someone is new to DataStores, they should not start off with trying to learn how to calculate offline revenue without understanding first how to utilise a DataStore. Learning the API and practical implementation of them is first necessary before adding any fancy features. Setting them in the right direction does nothing if they first don’t understand how the base concept works.

2 Likes

Perhaps I’m mistaken but I don’t think the user is having troubles with Datastore I think its actually calculating how long the user has been offline for. Correct me if I’m wrong as I could be :slight_smile:

2 Likes

[3]

Does this use a data store? If so, I don’t see it.