Player's team changes once, doesn't change again?
Hi, i'm making a Juggernaut Game with my friend, and the game works, once. All of the players team get changed to sheriff and juggernaut, and the game goes on normally, but then the second round starts, when only the juggernaut gets changed, but the sheriffs don't.
Is there any to fix it?
001 | local maps = game.ReplicatedStorage:WaitForChild( "Maps" ) |
002 | local juggernaut = nil |
003 | local players = game.Players:GetPlayers() |
004 | local revolver = game.ReplicatedStorage.Revolver |
005 | local knife = game.ReplicatedStorage.Knife |
007 | local gamestarted = false |
008 | local juggernautplrs = game.ReplicatedStorage.Values.JuggernautPlayers |
009 | local sheriffplrs = game.ReplicatedStorage.Values.SheriffPlayers |
010 | local spawnspawns = game.Workspace.Spawn.Spawns:GetChildren() |
011 | local gameending = false |
012 | game.Players.PlayerAdded:Connect( function (plr) |
013 | game.ReplicatedStorage.Values.plrs.Value = game.ReplicatedStorage.Values.plrs.Value+ 1 |
014 | table.insert(allplayers,plr) |
016 | game.Players.PlayerRemoving:Connect( function (plr) |
017 | game.ReplicatedStorage.Values.plrs.Value = game.ReplicatedStorage.Values.plrs.Value- 1 |
018 | table.remove(allplayers,FindIndex(allplayers,plr)) |
020 | function FindIndex(Table,Val) |
021 | for index,v in pairs (Table) do |
028 | local maplist = maps:GetChildren() |
029 | local map = maplist [ math.random( 1 ,#maplist) ] |
030 | local nmap = map:Clone() |
031 | local name = nmap.Name |
032 | nmap.Parent = workspace |
034 | game.ReplicatedStorage.Values.Status.Value = "Chosen Map: " ..name |
037 | if workspace:FindFirstChild( "Map" ) then |
038 | workspace.Map:Destroy() |
042 | if game.ReplicatedStorage.Values.plrs.Value > = 2 then |
043 | if gamestarted = = false then |
044 | if gameending = = false then |
045 | game.ReplicatedStorage.Values.Status.Value = "Loading Map..." |
049 | local juggernaut = allplayers [ math.random( 1 ,#allplayers) ] |
050 | table.remove(allplayers,FindIndex(allplayers,juggernaut)) |
051 | local spawns = game.Workspace:FindFirstChild( "Map" ).Spawns:GetChildren() |
052 | for i,Player in pairs (allplayers) do |
053 | local ngun = revolver:Clone() |
054 | ngun.Parent = Player.Backpack |
055 | Player.TeamColor = BrickColor.new( "Electric blue" ) |
056 | local Character = Player.Character |
057 | local chosenSpawn = spawns [ math.random( 1 ,#spawns) ] |
058 | Character:SetPrimaryPartCFrame(chosenSpawn.CFrame + Vector 3. new( 0 , 3 , 0 )) |
060 | juggernaut.Character:SetPrimaryPartCFrame(spawns [ math.random( 1 ,#spawns) ] .CFrame + Vector 3. new( 0 , 3 , 0 )) |
061 | local nknife = knife:Clone() |
062 | nknife.Parent = juggernaut.Backpack |
063 | juggernaut.TeamColor = BrickColor.new( "Really red" ) |
064 | juggernautplrs.Value = 1 |
065 | sheriffplrs.Value = game.ReplicatedStorage.Values.plrs.Value- 1 |
067 | game.ReplicatedStorage.Values.Status.Value = juggernaut.Name.. " is the juggernaut!" |
071 | game.ReplicatedStorage.Values.Status.Value = "Not enough players" |
073 | if gamestarted = = true then |
074 | if gameending = = false then |
075 | if juggernautplrs.Value = = 0 then |
076 | game.ReplicatedStorage.Values.Status.Value = "Game has finished, the sheriffs have won!" |
078 | for i,v in pairs (game.Players:GetChildren()) do |
079 | local hum = v.Character:WaitForChild( "Humanoid" ) |
087 | if sheriffplrs.Value = = 0 then |
088 | game.ReplicatedStorage.Values.Status.Value = "Game has finished, the juggernaut has won!" |
090 | for i,v in pairs (game.Players:GetChildren()) do |
091 | local hum = v.Character:WaitForChild( "Humanoid" ) |