How could I make a global daily reward system

Really basic question, But how could I (Every 12AM UTC - 5) Get a random quest from a table of quests, And select it as a global quest? I’m very unfamiliar with os.time so i’d appreciate it immensely if someone could perhaps help me break it down.

Thank you. :cool:

4 Likes

os.time() provides a precise timestamp, essentially a numerical record of the exact moment in time since January 1, 1970. It’s commonly used for tasks requiring accurate timekeeping, such as scheduling events or measuring elapsed time.: os | Documentation - Roblox Creator Hub

The code for your global Daily Reward System:

local QuestTable = {
	"Quest 1",
	"Quest 2",
	"Quest 3",
	-- Add more quests here
}

local function CheckAndSelectQuest()
	local randomIndex = math.random(1, #QuestTable)
	local selectedQuest = QuestTable[randomIndex]
	print("Selected Quest:", selectedQuest) -- Replace this line with your global quest 
end

local function GetNextTargetTime() -- Calculate the timestamp for 12AM UTC-5 on the current day
	local today = os.date("*t")
	today.year = today.year
	today.month = today.month
	today.day = today.day
	today.hour = 17 -- 12AM UTC-5 is 5 PM UTC
	today.min = 0
	today.sec = 0
	today.isdst = false -- Ensure daylight saving time is not considered

	local targetTime = os.time(today)

	-- If the target time has already passed, adjust for tomorrow
	if targetTime < os.time() then
		targetTime = targetTime + 24 * 60 * 60 -- Add one day in seconds
	end

	return targetTime
end

local function MainLoop()
	while true do
		local targetTime = GetNextTargetTime()
		local waitTime = targetTime - os.time()
		task.wait(waitTime)
		CheckAndSelectQuest()
	end
end

MainLoop()
1 Like

The simplest method would be to create an external API that would return the quest name/identifier and use HttpService to request it.
Then, you could make a simple os.time() check to see if it’s time for new quest and if so, update according to what the API returned.

A different approach would be using MemoryStoreService.
It doesn’t engage any external APIs but it’s less reliable and requires more planning and advanced checks to prevent multiple servers from updating current global quest.

3 Likes

nice useless chat gpt code that doesn’t relate to the question :clap:

2 Likes

Soo what makes u think i used gpt? Adding comments? :+1:

1 Like

not understanding the question and useless code

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.