Why does this script sometimes work and most of the time not?
Asked by
5 years ago Edited 5 years ago
Please provide more explanation in your question. If you explain exactly what you are trying to accomplish, it will be much easier to answer your question correctly.
I'm really confused because sometimes the script works but most of the time it breaks and I dont know why. No errors are given in the output. The problem is that a random player ("The beast") should be assigned to team "Beast" but most of the time this does not happen. When I look in the chat it says "You're now on team "Beast" ". However, after that the chat says "You're now on team Survivor". So the randomplayer gets assigned to beast but after that it gets assigned to team "Survivor". Could someone help me? Thanks in advance
Code:
10 | for i, plrs in pairs (game.Players:GetPlayers()) do |
14 | table.insert(players,plrs) |
19 | local randomPlayer = players [ math.random( 1 ,#players) ] |
20 | table.insert(beastPlayer,randomPlayer) |
24 | for i, beast in pairs (beastPlayer) do |
28 | if beast and beast.Character then |
29 | beast.TeamColor = BrickColor.new( "Really red" ) |
30 | table.remove(players,i) |
31 | beast.Character:FindFirstChild( "HumanoidRootPart" ).CFrame = |
33 | table.remove(spawnPoints, 1 ) |
35 | local beastInGame = Instance.new( "BoolValue" ) |
36 | beastInGame.Value = true |
37 | beastInGame.Name = "BeastInGame" |
38 | beastInGame.Parent = beast.Character |
41 | game.ReplicatedStorage.Weapons:WaitForChild( "Scythe" ):Clone() |
42 | clonedScythe.Parent = beast.Backpack |
50 | for i , player in pairs (players) do |
52 | if player and player.Character then |
54 | player.TeamColor = BrickColor.new( "Really black" ) |
55 | player.Character:FindFirstChild( "HumanoidRootPart" ).CFrame = |
57 | table.remove(spawnPoints, 1 ) |
59 | local inGameValue = Instance.new( "BoolValue" ) |
60 | inGameValue.Name = "InGame" |
61 | inGameValue.Value = true |
62 | inGameValue.Parent = player.Character |
66 | game.ReplicatedStorage.Weapons:WaitForChild( "Sword" ):Clone() |
67 | clonedSword.Parent = player.Backpack |
72 | table.remove(players,i) |