Why isn't my sword fighting mainscript not working properly?
So in this MainScript, I'm experiencing some issues. I looked at the output and everything seems fine, but when I tested it out, things weren't working. The game wasn't function properly. 2 players joined in, and they were getting teleported in and out of the lobby to the map in a short time and the GUI was announcing people winning in a matter of seconds. No one was even fighting or killing.
Thanks in advance!
Below is a server script inside ServerScriptStorage, named "MainScript"
003 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
005 | local ServerStorage = game:GetService( "ServerStorage" ) |
007 | local MapsFolder = ServerStorage:WaitForChild( "Maps" ) |
009 | local Status = ReplicatedStorage:WaitForChild( "Status" ) |
019 | Status.Value = "Waiting for enough players!" |
021 | repeat wait( 1 ) until game.Players.NumPlayers > = 2 |
023 | Status.Value = "Intermission" |
029 | for i, player in pairs (game.Players:GetPlayers()) do |
031 | table.insert(plrs,player) |
038 | local AvailableMaps = MapsFolder:GetChildren() |
040 | local ChosenMap = AvailableMaps [ math.random( 1 ,#AvailableMaps) ] |
042 | Status.Value = ChosenMap.Name.. " Chosen" |
044 | local ClonedMap = ChosenMap:Clone() |
045 | ClonedMap.Parent = game.Workspace |
049 | local SpawnPoints = ClonedMap:FindFirstChild( "SpawnPoints" ) |
051 | if not SpawnPoints then |
052 | print ( "Spawnpoints not found!" ) |
055 | local AvailableSpawnPoints = SpawnPoints:GetChildren() |
057 | for i, player in pairs (plrs) do |
059 | character = player.Character |
065 | character:FindFirstChild( "HumanoidRootPart" ).CFrame = AvailableSpawnPoints [ 1 ] .CFrame |
066 | table.remove(AvailableSpawnPoints, 1 ) |
070 | local Sword = ServerStorage.Sword:Clone() |
071 | Sword.Parent = player.Backpack |
073 | local GameTag = Instance.new( "BoolValue" ) |
074 | GameTag.Name = "GameTag" |
075 | GameTag.Parent = player.Character |
087 | Status.Value = "Get ready to play!" |
091 | for i = GameLegnth, 0 ,- 1 do |
093 | for x, player in pairs (plrs) do |
096 | character = player.Character |
098 | if not character then |
101 | if character:FindFirstChild( "GameTag" ) then |
103 | print (player.Name.. "is still in the game!" ) |
107 | print (player.Name.. " has been removed." ) |
112 | print (player.Name.. " has been removed." ) |
115 | Status.Value = "There are " ..i.. " seconds remaining, and " ..#plrs.. " players left." |
119 | Status.Value = "The winner is " ..plrs [ 1 ] .Name |
120 | plrs [ 1 ] .leaderstats.Bucks.Value = plrs [ 1 ] .leaderstats.Bucks.Value + reward |
122 | elseif #plrs = = 0 then |
123 | Status.Value = "Nobody won!" |
126 | Status.Value = "Time up!" |
134 | print ( "End of the game." ) |
136 | for i, player in pairs (game.Players:GetPlayers()) do |
137 | character = player.Character |
139 | if not character then |
142 | if character:FindFirstChild( "GameTag" ) then |
143 | character.GameTag:Destroy() |
146 | if player.Backpack:FindFirstChild( "Sword" ) then |
147 | player.Backpack.Sword:Destroy() |
150 | if character:FindFirstChild( "Sword" ) then |
151 | character.Sword:Destroy() |
155 | player:LoadCharacter() |
162 | Status.Value = "Game ended!" |