How would I add more time depending on how many players are in the game?

Heya There!!

I’m working on a wave system for a wave-based game and I’m trying to implement extra time if there are extra players in the game as a way to have people have the chance to get extra time to do whatever.

The issue is that I don’t know how to do so. I’m in the right track by checking to see if there multiple players in the game but after that, I’m stumped.

--[[SERVICES]]--
local ServerScriptService = game:GetService("ServerScriptService")
local Players = game:GetService("Players")

--[[BASE VARIABLES]]--
local BaseIntermissionTime = 25
local BaseWaveTime = 25
local CurrentEnemies = 0

--[[MODULE]]--
local WaveModule = {}


function WaveModule:Intermission()
	local PlayerCount = #Players:GetPlayers()
	
	--//Checking to see if they're is more than one player.
	if PlayerCount > 1 then
		--//If there are multiple players, add 5 seconds onto the timer.
		for _, Player in pairs(Players:GetPlayers()) do
			local PlayerList = {}
		end
		
	elseif PlayerCount == 1 then
		--//If there is only one player, continue.
		print("Solo run!! Continue.")
	end
end

function WaveModule:StartNewWave(WaveList, CurrentWave)
	for EntityName, EntitySettings in WaveList[CurrentWave] do
		print(EntityName)
		
		for Setting, Value in EntitySettings do
			print(Value)
		end
	end
end

return WaveModule

Not exactly sure what problem you are facing. If #Players:GetPlayers() > 1, add “extra time” to some variable.

If you’re talking about a linear increase in time, you can multiply the amount of players in the server, by some arbitrary constant and optional base time:

local Players = game:GetService("Players")

local function getWaveTime() -- pseudo function to get the time for the next wave
	local playerCount = #Players:GetPlayers() -- fetch the amount of players
	
	local secondsPerPlayer = 10 -- in seconds, the amount of time each player adds to each wave
	local additionalTime = secondsPerPlayer * playerCount -- the total additional time to add to the base time
	
	local baseTime = 100 -- in seconds, the base time the round has, without any players
	
	local waveTime = baseTime + additionalTime -- the amount of time the wave lasts
	
	return waveTime
end

Sorry if I wasn’t clear enough, I’m a bit tired so I might not be able to think straight. Basically, I want to add +5 seconds to the Intermission timer for every player in the server IF there is more than one player in the game.

The issue is that I don’t know how to get every player separately (If that makes sense) so for each player, they add +5 seconds.

Sorry if this also confuses you.

Is this timer for each player or the server? If it is for the server, you can do intermissionTimer += #Players:GetPlayers() * 5, just like how the other person wrote previously.

The entire server I guess. What do you mean by that exactly?

In simple words, do each player have their own separate timer or not?

No, players don’t have their own separate timer, so server then. Well then, thanks for the help!!
I’ll be using @bytenand answer but thanks for the help anyways.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.