Data Saving like Billionaire Simulator game

scripting

#18

I’ve already know about dataStoreService and httpService.


#19

I’m currently learning about os.time()


#20

Right. I most likely misread some of your posts or did not know that you already knew how to work the aforementioned two.

On that note though: no, HttpService is not involved and there is virtually no reason for it to be. The solution prior posted should be what you aim for.

The first thing you need is to check the time difference between player sessions. os.time() returns the number of seconds since January 1, 1970 (UNIX Epoch), so this essentially centralises your time. Once you have this, you can use something like os.difftime() to see how much time has passed between the last server a player joined and their current one. Finally, use this value to apply as a multiplier or divisor for any stats you may possess or want to scale against time, then add that to the player’s data.


#21

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


#22

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.


#23

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.


split this topic #24

5 posts were merged into an existing topic: Off-topic and bump posts

Please stay on the topic of the help request


#28

Interesting, thank you.


#30

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.

#32

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


#33

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.


#34

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.


#35

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


#36

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


#37

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

EDIT: Sorry for offtopic


#38

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


#39

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!


#40

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.


#41

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:


#42

[3]