How do I create a self updating synced shop?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want a shop that updates every 10 minutes, I just need something that can detect when it’s been 10 minutes so I can call a local function to update the shop, I need it to be synced across all servers.
  2. What is the issue? Include screenshots / videos if possible!
    I have looked all over the dev forum but there are only shops that update daily, nothing that updates every 10 minutes. I tried converting to update every 10 minutes but failed.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried everything available on the developer hub, I just can’t figure out how to make it every ten minutes.

This is my current code

local function toHMS(s) -- Just a function for time formatting
	return string.format("%02i:%02i:%02i", s/60^2, s/60%60, s%60)

function getAvailableItems(day)
	local rng = 
	local shopItems
	local item = items[rng:NextInteger(1, #items)]
	shopItems = item
	return shopItems

local shopupdater = coroutine.create(function()
	while wait(1) do
		local day = math.floor(((timemodule.time() + offset) / (60 * 60 * 24))/600)
		local t = (math.floor(timemodule.time())) + offset -- Sets the date to Thursday 5PM PST
		local origtime = t - offset
		local daypass = origtime % 86400
		local timeleft = 86400 - daypass
		local timeleftstring = toHMS(timeleft)
		local stringy = "New trail in: ".. timeleftstring -- Optional printout, obviously I'd use "timeleftstring" for a countdown timer in a shop
		if day ~= currentDay then
			currentDay = day
			currentShopItems = getAvailableItems(day)
			currenttrail = currentShopItems
			print('Updated shop items')		

You could just do a wait(600) to avoid extra code.

You could use modulo operation to do this.

An example usage would be something like this

local StartTime = tick()
local Interval = 10 * 60 -- 10 Minutes

while wait(1) do
    local TimePassed = math.floor(tick - StartTime) -- Finds the amount of seconds passed since the start of this script

    if TimePassed % Interval == 0 then
        print("10 minutes has passed") -- Here you can put whatever you want to happen every 10 minutes

So if you want every server to update in 10 minute at exactly the same time you can do:

while wait(1) do
    local timeString ="%X", os.time())
    local tkns = string.split(timeString, ":")
    if tkns[2] % 10 == 0 then
        --- update shop
        wait(60) -- wait to avoid updating again on same minute or create a variable to keep track of when shop was last updated


that doesnt update across servers

1 Like

Here is a discussion that helped me out when I was making something just like you are:

1 Like

I saw this but couldn’t figure out how to convert it into every 10 minutes.

1 Like

does this update across servers?

You could do that easily by making a predefined start time.