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

How Would I make a script that gives your 200 points every 12 hours(even when offline)

Asked by 10 years ago

I know I will get thumbs downs for this, but I have spent weeks on it and haven't figured it out

Any help? I am clueless at this point

3/26/2014 Update

Here's the rough script I have so far, please comment on any errors or glitches as I continue to make the script.

local DataStore = game:GetService("DataStoreService"):GetDataStore("Time")

game.Players.PlayerAdded:connect(function(player)
wait(3)
local label = player.PlayerGui.TimeLeft.Frame.TimeLeftLabel
local ready = player.PlayerGui.TimeLeft.Frame.Ready.ReadyToVisit
local key = "user_" .. player.userId    --we want to give 50 points to users each time they visit   
DataStore:UpdateAsync(key, function(oldValue)
local now = tick()
local later = oldValue or 300 --oldValue might be nil
local difference = math.abs(now - later)
local left = 300 - difference
if left < 0 then
    left = 0
end
repeat
label.Visible = true
local now = tick()
local later = oldValue or 300 --oldValue might be nil
local difference = math.abs(now - later)
local left = 300 - difference
if left < 0 then
    left = 0
end
label.Text = left
wait(0.1)
until left == 0 or ready.Value == true
label.Visible = false
ready.Value = true  
end) --DataStore End
end) --player enter end
1
I would think you could just save the time they joined the game and compare it with the last time they joined using tick(). The only minor issue you may face is a day in discrepancy because of the way ROBLOX handles server time. Kenetec wrote a function somewhere to handle tick() correctly so you can accurate do this. MrNicNac 855 — 10y
0
Thanks I will look into it and get back to you tkddude2 75 — 10y
0
I looked into tick a little and I am just curious, I know when you use tick() in a local script it finds the computers local time, but could it be changed if you changed you computers time? tkddude2 75 — 10y
1
Use os.time(). Articulating 1335 — 10y
0
Articulating is absolutely right. Before os.time() we had to use Kenetecs method, which used HttpService to synchronize. tick() returns the local time, which can be in the worst case 24 hours off. os.time() returns what you want here, the true UNIX time, which is the same on every device out there. jobro13 980 — 10y

1 answer

Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
10 years ago

Record the time the player first joins. Each next time the player joins, check the time and see if it has been 12 hours.

local data=game:service("DataStoreService"):GetDataStore("Points")

game.Players.PlayerAdded:connect(function(player)
    local time=player:LoadNumber("JoinTime")
    if time==0 then
        player:SaveNumber("JoinTime",os.time())
    else
        local reps=math.floor((os.time()-time)/12/60/60)
        if reps<0 then
            data:IncrementAsync(player.Name,reps*200)
            player:SaveNumber("JoinTime",time+reps*12*60*60)
            wait(time-reps*12*60*60)
            player:SaveNumber("JoinTime",os.time())
            data:IncrementAsync(player.Name,200)
        end
    end
    while wait(12*60*60)do
        player:SaveNumber("JoinTime",os.time())
        data:IncrementAsync(player.Name,200)
    end
end)

This stores players' points in datastore and their time playing in data persistence. It calculates the amount of time that has passed since they were last there and rounds it down to a multiple of 12 hours and multiplies that by 200 for the amount of points to be incremented. When they come back, their timer is not reset; it keeps the remaining time until the next 12 hours.

Ad

Answer this question