Here you’re still using the same offset variable you used for days (which was in hours)
Use a separate variable for the week offset and make sure it’s in days.
Same thing for the other variables now that I look at it. Make sure you make different variables for the week calculations and day calculations, you’re using the variables for day calculations for everything
If you want the shop only to be updated weekly, you should change your wait(1) to probably wait(60) (or even higher). Checking every second isn’t needed and only uses memory, which can cause lag
I am trying to figure out how to apply a offset variable for the week, I want the new week to start on a monday.
local DayOffset = 4
local WeekOffset = --??
local Week = math.floor((SyncedTime.time() + WeekOffset) / (60 * 60 * 24 * 7)) -- im not sure if this is right, but it does give me the right week
I tested your script and there’s an error at this line of code:
repeat
shopitem = itemtablecopy[rng:NextInteger(1,#itemtablecopy)] -- ERROR
until shopitem ~= item -- until you get one that the shop table doesn't have yet
Whenever you try to run this line and get more than 5 items (6 or more than 6), it has a bug saying ServerScriptService.ShopUpdater:101: Script timeout: exhausted allowed execution time
currentShopItems = getAvailableItems(day, 5) -- Get 5 items and supply the day as the seed, then set our currentShopItems table to the table we get from this function.
I know what the error means but how can I fix that? I tried adding a wait but when running the code, it gets stuck on “Respinning…”.
Edit: It’s weird that after it goes to 00:00:00, it will only just run the loop again without
making changes to daily shops.
Edit2:
Apparently it doesn’t print after the countdown ends, I’m assuming this is a bug. (Screenshot above for output)
if day ~= currentDay then -- If the day variable isn't equal to currentDay (so when the day variable changes...)
print("c")
Wow nice totorial! I have a couple questions though. If you are fetching the time from a google website, would it matter if someone used a different engine, like bing, or yahoo, or a different computer like a Mac?
And,
So you are saying, if I had let’s say ten items, you would want me to only use 8 and just not use the other two(sorry if that seems like a silly question, I am still trying to understand the concepts you are using!)
Windows or Mac doesn’t matter, on the term of a different website I’m not sure. I’m pretty sure if the other sites have a way to fetch time they’d return UTC, just like Google, so I don’t think it matters.
Yes. Think of it like this. Say you want to have 11 chosen items for the shop, but you only have 10 to choose from, and you don’t want any duplicates. Since the amount you want is more than the amount you have, it’s impossible to fill the extra slot without having a duplicate. 10 items would fill 10 slots, but you still have 1 extra one remaining. You can’t fill it without a dupe because everything has been used already
I am having an issue though. The time says it will reset at 5:00 PM (I used the -3 offset), and the time does actually reset like it is supposed to. The problem is the shop items don’t actually reset until the morning after, or sometime after 9:00 at night. Aren’t they supposed to be connected? Do you know off the top of your head what might be wrong or should I send code?
i know i’m late but i’m looking for help on this problem too it doesnt update live in-game so you have to rejoin the server
Found a fix by changing + to - in local day = math.floor((syncedtime.time() - offset) / (60 * 60 * 24))