You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve?
i’m making a gacha system for my game, and i want to reset the featured item when it reaches midnight. -
What is the issue? it doesn’t really work. it detects midnight, but it doesn’t roll the number.
ad there is no error warnings when i look at the output. -
What solutions have you tried so far? i have looked at a lot of other topics and tutorial, but didn’t find anything particularly useful.
my code :
function Format(Int)
return string.format("%02i", Int)
end
function convertToHMS(Seconds) -- Converts seconds into hours, minutes, and seconds
local Minutes = (Seconds - Seconds%60)/60
Seconds = Seconds - Minutes*60
local Hours = (Minutes - Minutes%60)/60
Minutes = Minutes - Hours*60
return Format(Hours)..":"..Format(Minutes)..":"..Format(Seconds)
end
while wait(0.5) do
local Time = os.time()
local date = os.date("!*t", Time) --Gets the Universal Standard time as a table
local secondsOfTheDay = date["hour"]*3600 + date["min"]*60 + date["sec"] -- Finds how many seconds have passed in the day
local secondsLeftUntilMidnight = convertToHMS(86400 - secondsOfTheDay) -- There are 86400 seconds in a day, so this finds how much time is left.
print(secondsLeftUntilMidnight)
if 86400 - secondsOfTheDay == 0 then -- If there are 0 seconds left of the day then do stuff
local storage = game:GetService("ReplicatedStorage")
local id = storage.Values:WaitForChild("FeaturedID")
local chance = math.random(1, 11)
id.Value = chance
end
end