You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
Okay so I am new about scripting and just started learning about os.time,os.clock etc and want to reset daily rewards on a specific time like let’s say UTC+2 9am
What is the issue? Include screenshots / videos if possible!
I Don’t know how to do it
I made a basic script that resets the daily reward for client every 24 hours after player gets it
But I am trying to turn it to server daily reset
DailyReward.Touched:Connect(function(hit)
local player = players:GetPlayerFromCharacter(hit.Parent)
if player then
if os.time() >= (player.DailyReward.Value) then
player.DailyReward.Value = os.time() + 86400
end
end
end)
What solutions have you tried so far?
I tried checking youtube and previous post but have no idea about how to reset every daily cooldowns at one time for server not client
I don’t know if the answer is no or yes. like I said I just started learning about os.time so, I don’t know much how to use os.time for server daily reset. all post I saw about os.time was for adding cooldowns like the code I write
what is the point of this? like how telling the server they got the reward will help with daily reward?
I feel like I couldn’t explain my question
like if a player get’s the daily chest at 16.00 I want player to reclaim the chest at 00.00
and if another player get’s the daily chest at 14.00 I also want that player to be able to reclaim the chest at 00.00
You should learn about RemoteEvents, and use them to handle the part:
if os.time() >= (player.DailyReward.Value) then
player.DailyReward.Value = os.time() + 86400
end
On a ServerScript. If you have a datastore already that can remember the daily reward or keep track of player’s money, you could implement the time for daily reward there.
My bad, I thought you were trying to comunicate from client to server, ideally this should be done on the server
Now this I can answer:
DailyReward.Touched:Connect(function(hit)
local player = players:GetPlayerFromCharacter(hit.Parent)
if player then
if math.floor(os.time()/86400) > (player.DailyReward.Value) then
player.DailyReward.Value = math.floor(os.time()/86400) -- gets the day
end
end
end)
I guess only way to detech if it is working or not. is waiting 2 hours and 55 minutes (which is time remained until new day acording to os.time)
Thanks! I will inform later if it is working or not!
I just tested and yeah it work’s Thanks. but I wondered somethink else, how can change the reset time to 01.00 not 00.00 adding a hour and changing os.time to (90000) will make it 25 hours I am confused about this a little bit
os.time{
year=2023, month=4, day=6, -- Date components
hour=3, min=0, sec=0 -- Time components
}
-- if time.os returned a time on 4/6/2023 (mm/dd/yyyy) at 2:00am or 2:00
-- this would return a time 1 hour after then, with an hour of 3 or 3:00am
this is a diffucult question why shouldn’t I want it like that?
by the way. is this how should script should look like to set reset time to 01.00?
DailyReward.Touched:Connect(function(hit)
print(math.floor(os.time()/86400))
local SavedTime =(os.time{
year=2023, month=4, day=7, -- Date components
hour=1 -- Time components
})
local player = players:GetPlayerFromCharacter(hit.Parent)
if player then
if SavedTime < os.time() -86400 then
SavedTime = os.time()
if math.floor(os.time()/86400) > (player.DailyReward.Value) then
--if os.time() >= (player.DailyReward.Value) then
player.DailyReward.Value = math.floor(os.time()/86400)
end
end
If you set the value with os.time by touching the part it won’t save once the player leaves. Which is why you have to use DataStoreService which is a service specifically made for saving player data to save it.