Query regarding round script efficiency

Hi, so I have a game that operates on a round script and the round works in a countdown for loop like so:

for i = length,0,-1 do

		local royals = {}
		local assassins = {}

		for i, player in pairs(game.Players:GetPlayers()) do
			if player:WaitForChild("SelectedTeam").Value == "Bodyguards" or player:WaitForChild("SelectedTeam").Value == "King" or player:WaitForChild("SelectedTeam").Value == "Blacksmith" then
				table.insert(royals, player)
			elseif player.SelectedTeam.Value == "Assassins" then
				table.insert(assassins, player)


		status.Value = toMS(i)

		if #royals == 0 then
			outcome = "Assassins-Win!"


		if #assassins == 0 then
			outcome = "Royals-Win!"

		if i == 0 then
			outcome = "Out-Of-Time"


What id like to implement is, if the King dies during the round, the timer on the round automatically snaps to 30 seconds left, creating an avenge period that the rest of the ‘royals’ team must eliminate the ‘assassins’ team or they win. My question is, what is the most efficient method to achieve this? (Regarding server performance and overall efficiency)

I have a died function as follows:


However this is in a separate server script, so im not sure if this could be used to then send data over to the game server script?

P.s To tell the teams and the players apart, each person has a stringValue, and the value of this will tell you their team. (I also have actual studio teams set up aswell)

Any help would be appreciated

1 Like

You could make an int value and for example put it in serverstorage which is used as timer. Before the round starts you just give it the value of how long the round will last

instead of for use while for example

while(game.ServerStorage.length.Value >= 0)

length is the int value

if game.ServerStorage.length.Value == 0 then
			outcome = "Out-Of-Time"

        game.ServerStorage.length.Value -= 1

you need to lower the value of length for 1 each second so that it counts down
when king dies you can just set the value of length to 30 even though it’s in another script

game.ServerStorage.length.Value = 30
1 Like

Sorry for the late reply. This is a really intuitive way to go about it, was able to implement it with ease and it worked perfectly. Thank you so much!

Hi, sorry to ask but can you shine any light on this? Having a very strange issue here…


	for i, plr in pairs(game.Players:GetPlayers()) do
		if not plr:FindFirstChild("InMenu") then
			if plr.SelectedTeam.Value == "King" then
				plr.Team = teams["King"]
			elseif plr.SelectedTeam.Value == "Bodyguards" then
				plr.Team = teams["Bodyguards"]
			elseif plr.SelectedTeam.Value == "Assassins" then
				plr.Team = teams["Assassins"]
			elseif plr.SelectedTeam.Value == "Blacksmith" then
				plr.Team = teams["Blacksmith"]

So I have this in a serverscript that should send the relevant players through the remoteevent to this local script:

	if v.Team == teams["King"] then
		local kingIconClone =kingIcon:Clone()
		kingIconClone.Parent = Royals
		if v.SelectedTeam.Value == "Dead" then
			kingIconClone.Cross.Visible = true

However, on printing v, it returns nil? when it should return a player? Very confused by this. (Also ignore the lack of ‘ends’, some are missing just for copy and pasting the relevant info)
Thank you

Problem is that you’re actually not sending any data. Depending on whether you want to send that data just to one player or all players in server there are two functions.
please read their documentation

1 Like

Yeah, I figured it out not too long after I messaged, apologies, deleted the messages after to imply it was fine, shouldve deleted the post altogether though.