Continually occuring Events

Hello everyone!

Currently, I am working on a project where there are repeated “Phases”. The players in the game are asked to do something each phase. The information received from each phase is vital for the game going forward, so I want to make sure that it is saved. These phases will come together to form a Week in game. Each week is separate from the other weeks before and ahead of them. I’m going to clear the data from the previous week every time a week ends.

The only issue I have, right now, is making it so these Phases and Weeks are ongoing until a certain point. I want the weeks to repeat, as well as the phases inside each week, so the game runs smoothly.

Let me give an example. In Week1, there is Phase1. When this phase ends, Phase2 will automatically begin. Then Week1 will end, and a new week will take its place with a new Phase1 and Phase2.

How would I handle it on the server? Would I use RemoteEvents, making it so each event fires on the server and replicates on the client repeatedly? And then when the phase ends, it would fire back to the server? Or would this be unnecessary communication?

Another question: Would I want to combine the continually repeating phases into one script? Or have a series of scripts that activate when certain Events are fired?

I just want to understand which would be better for the server and individual clients to handle. I, of course, can provide more detail if this is too confusing. Thank you in advance.

1 Like

Seems like you can just use a while loop on the server and have an remote event fire to all clients to let everyone know that a new week has started. It would probably look something like this:

--Variables
local MaxPhases = 5
local PhaseTime = 60 --One Minute

local week = 0
local phase = 0
while true do
	phase = 0
	
	--Increment and Inform
	week = week + 1
	NewWeekEvent:FireAllClients(week)
	
	--Phase Loop
	repeat
		phase = phase + 1
		NewPhaseEvent:FireAllClients(phase)
		wait(PhaseTime) --Duration between phases
	until phase >= MaxPhases
	
end

This is a loop for a week of 5 Phases with 60 minute phases so a 5 minute week. Hopefully this helps!

I understand.

Could I possibly use this as a controller? When the phase value is a certain number, could I fire an event special to this value?

Sure! An easy way to do this would be to have the clients recognize that a certain phase is a special one. But if you wanted to use separate events you could change the phase loop to this:

--Phase Loop
repeat
	phase = phase + 1
	if phase == 3 then
		SpecialPhaseEvent:FireAllClients(phase)
	else
		NewPhaseEvent:FireAllClients(phase)
	end
	wait(PhaseTime) --Duration between phases
until phase >= MaxPhases

In this case something special happens on Phase 3.

1 Like