Why is my sword fighting game not working?
I am trying to make a sword fighting game but it's not working. I haven't got any errors but I am not teleporting to the map. Please help me! Here is the script:
-- Define Variables
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local MapsFolder = ServerStorage:WaitForChild("Maps")
local Status = ReplicatedStorage:WaitForChild("Status")
local GameLength = 60
local reward = 10
-- Game loop
while true do
001 | Status.Value = "Waiting for at least 2 players.." |
003 | repeat wait( 1 ) until game.Players.NumPlayers > = 2 |
005 | Status.Value = "Intermission" |
011 | for i, player in pairs (game.Players:GetPlayers()) do |
013 | table.insert(plrs,player) |
019 | local AvailableMaps = MapsFolder:GetChildren() |
021 | local ChosenMap = AvailableMaps [ math.random( 1 ,#AvailableMaps) ] |
023 | Status.Value = ChosenMap.Name.. " Chosen" |
025 | local ClonedMap = ChosenMap:Clone() |
026 | ClonedMap.Parent = workspace |
030 | local SpawnPoints = ClonedMap:FindFirstChild( "SpawnPoints" ) |
032 | if not SpawnPoints then |
033 | print ( "Spawnpoints not found!" ) |
036 | local AvailableSpawnPoints = SpawnPoints:GetChildren() |
038 | for i, player in pairs (plrs) do |
040 | character = player.Character |
042 | if not character then |
045 | character:FindFirstChild( "HumanoidRootPart" ).CFrame = AvailableSpawnPoints [ 1 ] .CFrame |
046 | table.remove(AvailableSpawnPoints, 1 ) |
051 | local Sword = ServerStorage.Sword:Clone() |
052 | Sword.Parent = player.Backpack |
054 | local GameTag = Instance.new( "BoolValue" ) |
055 | GameTag.Name = "GameTag" |
056 | GameTag.Parent = player.Character |
068 | Status.Value = "FIGHT!" |
072 | for i = GameLength, 0 ,- 1 do |
074 | for x, player in pairs (plrs) do |
077 | character = player.Character |
079 | if not character then |
082 | if character:FindFirstChild( "GameTag" ) then |
084 | print (player.Name.. " is still in the game" ) |
088 | print (player.Name.. " has been removed" ) |
093 | print (player.Name.. " has been removed" ) |
097 | Status.Value = "There are " ..i.. " seconds remaining, and " ..#plrs.. " players left" |
101 | Status.Value = "" ..plrs [ 1 ] .Name " celebrated ninja day so they won" |
102 | plrs [ 1 ] .leaderstats.Godbucks.Value = plrs [ 1 ] .leaderstats.Godbucks.Value + reward |
104 | elseif #plrs = = 0 then |
105 | Status.Value = "No one celebrated ninja day.." |
108 | Status.Value = "Time's up!" |
end
print ("End of game")
for i, player in pairs(game.Players:GetPlayers()) do
character = player.Character
04 | if character:FindFirstChild( "GameTag" ) then |
05 | character.GameTag:Destroy() |
08 | if player.Backpack:FindFirstChild( "Sword" ) then |
09 | player.Backpack.Sword:Destroy() |
12 | if character:FindFirstChild( "Sword" ) then |
13 | character.Sword:Destroy() |
end
ClonedMap:Destroy()
Status.Value = "Game ended"
wait(5)
end