Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I increase the timer by players in the server?

I am trying to create a timer, but I want the timer to be fair by calculating all the players and giving the appropriate time.

For example, if one player joins the game then the timer will be 30 seconds, or if two players joined then it will be 60 seconds. How do I input this "method" into my timer? Any hints would be appreciated!

wait(1)
	ftime = ftime - 1
	text.Value = "Time remaining: "..ftime
		
	local function TeamMembers(name)
		local players = {}
		for _, plr in pairs(game.Players:GetPlayers()) do
			if plr.Team and plr.Team.Name == name then
				table.insert(players, plr)
			end
		end
		return players
	end

1 answer

✓ Accepted answer

to get the number of seconds you can use tables and some simple math

to get the number of players in the server do

local NumOfPlayers = table.getn(game.Players:GetChildren())

to get the amount of seconds to wait do

local SecsToWait = NumOfPlayers * 30

For example if 4 players were in this server then SecsToWait would be 120 seconds

5 comments

0

Thank you! I will try it now.

0

What if it's a server script? I'm getting 0 on server script except for local script.

0

makes no difference

0

if ur getting 0 it means the script is running before any players have finished loading, you may want to add a wait(10) or smth like that to it

0

Ok!

This discussion is preserved as it was. New answers, comments, and votes are closed.