I am trying to make a function that moves all the players once an event happens, the function worked fine until I put a debounce in, then suddenly 2-3 players from the table would not be moved. I believe this is due to my use of coroutines, can think of reasons why this is happening?
jailed is a table of players, the players are meant to have the for loop done to them (remove/change their table, move their characters etc) but some of the people in the jailed table are left out as soon as I added in the debounce.
function jailbreak(player) if jbdb == true then jbdb = false lastman = nil someoneDied = false game.Lighting.FogEnd = 100000000 numJb = numJb + 1 for i,v in pairs(criminals) do if v.Character and v.Character.Humanoid and v.Character.Humanoid.Health > 0 and v.Character.Head and (unlock.Position - v.Character.Head.Position).magnitude < 80 then v.Character:MoveTo(currentMap.CopSpawns:GetChildren()[math.random(1,6)].Position) end end for i,v in pairs(jailed) do stopSpec:FireClient(v) if v.Character and v.Character.Torso and v.Character.Humanoid and v.Character.Humanoid.Health > 0 then makeCriminal(v) wait() v.Character:MoveTo(currentMap.CopSpawns:GetChildren()[math.random(1,6)].Position) local CopNum = v:FindFirstChild("CopNum") CopNum.Value = defaultJail if v.Character.Torso then local spar = Instance.new("Sparkles",v.Character.Torso) coroutine.wrap(function() wait(8) if v and v.Character and v.Character.Humanoid then v.Character.Humanoid.WalkSpeed = 16 spar:remove() end end)() end v.Character.Humanoid.WalkSpeed = 40 end end for i,v in pairs(criminals) do Restrictions:FireClient(v,false,Restrs) end if player and player.Character and player.Character.Humanoid then player.Character:MoveTo(currentMap.CopSpawns:GetChildren()[math.random(1,6)].Position) local CopNum = player:FindFirstChild("CopNum") CopNum.Value = defaultJail local spar = Instance.new("Sparkles",player.Character) player.Character.Humanoid.WalkSpeed = 40 coroutine.wrap(function() wait(8) player.Character.Humanoid.WalkSpeed = 16 spar:remove() end)() end Event:FireAllClients("Jailbreak") coroutine.wrap(function() wait(38) jbdb = true if someoneDied and #criminals > 0 and #jailed > 0 then for i,v in pairs(criminals) do Restrictions:FireClient(v,"clear",Restrs) end someoneDied = false else numJb = 0 end end)() end end