How do I fix this?

local date = os.date("!*t", os.time())

local crystalModule = require(game.ReplicatedStorage.Modules.CrystalDropParty)
local cocoaModule = require(game.ReplicatedStorage.Modules.CocoaDropParty)

local function crystalDropParty()
	local CurrentSec = date.min * 60 + date.sec
	
	local HalfHourSec = 60 * 20
	
	local TimeToWait = HalfHourSec - CurrentSec
	print(TimeToWait)
	
	if TimeToWait < 0 then
		TimeToWait = 2 * HalfHourSec - CurrentSec 
		print(TimeToWait)
	end

	wait(TimeToWait)
	
	repeat
		crystalModule.StartDropParty()
		wait(HalfHourSec)
	until os.time() ~= os.time({year = 2020; month = 5; day = 10})
end

local function cocoaDropParty()
	local CurrentSec = date.min * 60 + date.sec
	
	local HalfHourSec = 60 * 15
	
	local TimeToWait = HalfHourSec - CurrentSec
	print(TimeToWait)
	
	if TimeToWait < 0 then
		TimeToWait = 2 * HalfHourSec - CurrentSec 
		print(TimeToWait)
	end

	wait(TimeToWait)
	
	repeat
		cocoaModule.StartDropParty()
		wait(HalfHourSec)
	until os.time() ~= os.time({year = 2020; month = 5; day = 10})
end

if date.year == 2020 and date.month == 5 and date.day == 10 then
	crystalDropParty()
	cocoaDropParty()
else
	local timeUntilDate = os.time({year = 2020; month = 5; day = 10}) - os.time()
	print(timeUntilDate)
	
	wait(timeUntilDate)
	
	crystalDropParty()
	cocoaDropParty()
end

So I just tested this code and when I call the functions, it goes through the first function first until going to the second function.

So how would I make the functions both start at the same time?

You could use coroutine.wrap.

coroutine.wrap(crystalDropParty)()
coroutine.wrap(cocoaDropParty)()

Simply wrap both function, or just one, in a coroutine:

coroutine.wrap(function()
    crystalDropParty()
end)()
cocoaDropParty()

Edit, have to wait 4 hours to delete the post. Dang it. Using mobile sucks.

1 Like