I am coding a sword game and i got an error that says "Expected got 'else' " here is line of code and this code is the main game loop, most of the game logic is in this script, and that error is holding my whole project back 164 lines, problem around line 110

-- Define Variables

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local SeverStorage = game:GetService("ServerStorage")

local MapsFolder = SeverStorage:WaitForChild("Maps")

local Status = ReplicatedStorage:WaitForChild("Status")

local GameLength = 80

local reward = 10

-- Game Loop

while true do
	
	Status.Value = "Waiting for enough players"
	
	repeat wait() until game.Players.NumPlayers >= 2
	Status.Value = "Intermission"
	
	wait(15)
	
	local plrs = {}
	
	for i, player in pairs(game.Players:GetPlayers()) do
		table.insert(plrs,player) -- Add Player To Players Table
	end
	end
	
	wait(2)
	
	local AvailableMaps = MapsFolder:GetChildren()
	
	local ChosenMap = AvailableMaps[math.random](1,#AvailableMaps)
	
	Status.Value = ChosenMap.Name.." Chosen"
	
	local ClonedMap = ChosenMap:Clone()
	ClonedMap.Parent = workspace
	
	--Teloport Players to map.
	
	local SpawnPoints = ClonedMap:FindFirstChild("SpawnPoints")
	
	if not SpawnPoints then
		print("No Spawnpoints Available")
	end
	
	local AvailableSpawnPoints = SpwanPoints:GetChildren()
	
	for i, playe in pairs(plrs) do
		if player then
			character = player.Character
			
			if character then
				-- Teleport Player
				
				character:FindFirstChild("HumanoidRootPart").CFrame = AvailableSpawnPoints[1].CFrame
				table.remove(AvailableSpawnPoints,1)
				
				
				-- Give Sword
				local Sword = SeverStorage.Sword:Clone()
				Sword.Parent = player.Backpack
				
				local GameTag = Instance.new("BoolValue")
				GameTag.name = "GameTag"
				GameTag.Parent = player.Character
				
			else
				-- No Character
				if not player then
					table.remove(plrs,i)
				end
			end
		end
	end
	
	Status.Value = "Game is starting"
	
	wait(2)
	
	for i = GameLength,0, -1 do
		
		for x, player in pairs(plrs)do
			if player then
				
				character = player.Character
				
				if not character then
					-- They Left
				else
					if character:FindFirstChild("GameTag") then
						
					-- Still alive
					print(player.Name.." is still in the game")
				else
					-- They died
					table.remove(plrs,x)
					print(player.Name.." was elimanated!")
				end
				end
			end
		end
	end

		else  -- Problomatic line
			table.remove(plrs,x)
			print(player.Name.." was elimanated!")
			end
			
			Status.Value = "There are "..i.." seconds remaining, and "..#plrs.." players remaining"
			
			if #plrs == 1 then
				--Winner
				Status.Value = plrs[1].Name.."Has won the match"
				plrs[1].leaderstats.Points.Value = plrs[1].leaderstats.Points.Value + reward
				break
			elseif #plrs == 0 then
				Status.Value = "Draw"
				break
			elseif i == 0 then
				Status.Value = "Time up!"
				break
			end
		
		wait(1)
	end
	
	print("Game ended")
	
	for i, player in pairs(game.Players:GetPlayers()) do
		character = player.Character
		
		if not character then
			
		end
		-- ignore
		end
			else
				if character:FindFirstChild("GameTag") then
					character.GameTag:Destroy
				end
				
				if player.backpack:FindFirstChild("Sword") then
					player.Backpack.Sword:Destroy()
				end
				if character:FindFirstChild("Sword") then
					character.Sword:Destroy()
				end
			end
			player:LoadCharacter()
	end
	
	ClonedMap:Destroy()
	
	wait(2)
	
	Status.Value = "Game ended"
	
end

please help thanks

13 comments

0

why do you have 4 ends.... and where is the if statement, what did you even do xD

0

Show the full script or we can't really help you.

0

ok

0

Provide full script

0

updated with full script

0

full script add

0

i added the full script

0

A lot of problems would become apparent if you formatted your code correctly.

0

thats the raw format from studio

0

Run it through this plugin and the formatting issues will stand out https://www.roblox.com/library/592898457/Script-indenter

0

how does it work?

0

My guess is that it's just because you ended your loop but then tried to use else to refer to it

0

It seems to me, once i went through all the loops, that the else section with the problems is already placed in the line of code above it (making it redundant unless you have certain circumstances for it?) otherwise there is no if / then statement paired with the else section, which is why it expects the end of function