Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
3

Daily Login Award?

Asked by
Omarstein 100
9 years ago

First of all I would like to start by saying this is not a request, but rather a question. I've seen this in many games and I've always wondered how such implementation is accomplished. For instance, lets take The Mad Murderer into account, how did Loleris implement the daily award system in which you would get a certain amount of credits every 12 hours?

1 answer

Log in to vote
3
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

Basically, he saves an integer representing the time that the player last earned the reward. Then, he compares this integer to the current time, and see if more than 12 hours have passed. I'm too lazy to get out my datastore reference to actually write working code, but here's how it would look:

game.Players.PlayerAdded:connect(function(player)
    if os.time() - getLastRewardTime(player) > 60*60*12 then
    -- seconds/minute * minutes/hour * hours
        rewardPlayer(player)
    end
end)

This assumes that the rewardPlayer function sets the LastRewardTime that getLastRewardTime is accessing. If LastRewardTime doesn't exist, the function returns 0.

I used os.time() instead of tick() for reasons you should read about here. Keep in mind that you should only get relative place visit times from Scripts and not LocalScripts.

Ad

Answer this question