how to count down 1 day even when the player is not in the game
ok first off why do you need to do this? In which case are you going to use this? Cause depending on that the right method can vary
daily gifts for players every day
Use timestamps. If you’re using it for daily rewards for example, save the timestamp the player claimed the daily. Then, when a player rejoins, get the timestamp and subtract. The remaining time (if positive) would be how much longer the player has to wait for the daily. If 0 or negative, then that means the player has already waited enough time to claim the daily.
so what you should do instead is save when the player was last in the game with like OS.date or time or whatever, then you look at the current date and see if its in time where they should get a reward
show an example in code please
I can show you!
charcharcharcharcharr
Ok so for starters:
With said date youll need to save it using datastores:
and yup. If you dont know how to put these things together then please go learn the basics of stuff, itll help you a lot.
Anyhow I dont use os often so I dont exactly know the best ways to do this so Imma let @MisterGrinch2017 take it from here
-- Server script
-- Service
local Players = game:GetService("Players")
local tableWithTimestamp = {}
local day = 24 * 60 * 60 -- secs
local function getTimestamp()
return os.time()
end
function ClaimDaily(player)
-- do code to claim daily
tableWithTimestamp[player] = os.time()
end
Players.PlayerAdded:Connect(function(player)
if tableWithTimestamp[player] - os.time() <= 0 then
print("can receive daily")
end
end)
thanks @MisterGrinch2017 and @FroDev1002 for help!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.