Having trouble making a juggernaut system

im trying to make a round system alongside with a juggernaut system
the juggernaut system doesnt work for some reason, i tried to fix it multiple times but it wont let me become a juggernaut after the round has ended

for the juggernaut system, after the round ends, theres a grace period for someone to become a juggernaut, and once someone does, that person becomes the jug and locks everyone else from becoming the juggernaut.

local rs = game.ReplicatedStorage

local maps = rs:WaitForChild(“Maps”)
local res = rs:WaitForChild(“RemoteEvents”)

local numMapsVoting = 3
local intermissionTime = 5
local voteTime = 10
local roundTime = 10
local jugGraceTime = 10
local jugTime = 15

local plrVotes = {}

function addVote(plr:Player, mapName:string)

plrVotes[plr] = mapName
res:WaitForChild(“Voted”):FireAllClients(plrVotes)
end

function removePlayerVote(plr:Player)

plrVotes[plr] = nil
res:WaitForChild(“Voted”):FireAllClients(plrVotes)
end

function loadMap(mapName:string)

local newMap = maps[mapName]:Clone()
newMap.Parent = workspace.Arena.Mainmap

return newMap
end

function removeMap(map:Instance)

map:Destroy()

for _, plr in pairs(game.Players:GetPlayers()) do
plr:LoadCharacter()
end
end

function handleRound()

local plrsAlive = {}
for _, plr in pairs(game.Players:GetPlayers()) do

  if plr.Character and plr.Character.Humanoid.Health > 0 then
  	table.insert(plrsAlive, plr)
  	
  	plr.Character.Humanoid.Died:Connect(function()
  		table.remove(plrsAlive, table.find(plrsAlive, plr))
  	end)
  end

end
script.Time.Value = roundTime
repeat
task.wait(1)
script.Time.Value = script.Time.Value - 1
until script.Time.Value <= 0
script.Time.Value = 0
task.wait(1)
script.RoundEnd.Value = true

end

res:WaitForChild(“Voted”).OnServerEvent:Connect(addVote)

game.Players.PlayerRemoving:Connect(removePlayerVote)

while true do

script.Time.Value = intermissionTime
repeat
task.wait(1)
script.Time.Value = script.Time.Value - 1
until script.Time.Value <= 0
script.Time.Value = 0

local mapsToVote = maps:GetChildren()

while #mapsToVote > numMapsVoting do
table.remove(mapsToVote, math.random(1, #mapsToVote))
end

plrVotes = {}

res:WaitForChild(“VotingBegun”):FireAllClients(mapsToVote)

script.Time.Value = voteTime
repeat
task.wait(1)
script.Time.Value = script.Time.Value - 1
until script.Time.Value <= 0
script.Time.Value = 0

local highestVotedFor = nil

local votes = {}
for i, map in pairs(mapsToVote) do
votes[map.Name] = 0

  if i == 1 then
  	highestVotedFor = map.Name
  end

end

for plr, vote in pairs(plrVotes) do

  if votes[vote] then
  	votes[vote] += 1
  	
  	if votes[highestVotedFor] < votes[vote] then
  		highestVotedFor = vote
  	end
  end

end

res:WaitForChild(“VotingEnded”):FireAllClients()

local newMap = loadMap(highestVotedFor)

handleRound()
repeat
task.wait(1)
until script.RoundEnd.Value == true
script.RoundEnd.Value = false
removeMap(newMap)
end

1 Like

i fixed it, i just had to add task.wait() to one of the lines

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