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
why do you have 4 ends.... and where is the if statement, what did you even do xD
Show the full script or we can't really help you.
ok
Provide full script
updated with full script
full script add
i added the full script
A lot of problems would become apparent if you formatted your code correctly.
thats the raw format from studio
Run it through this plugin and the formatting issues will stand out https://www.roblox.com/library/592898457/Script-indenter
how does it work?
My guess is that it's just because you ended your loop but then tried to use else to refer to it
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