Errors with the Code

Still says expected end line 107

Can you please show the full code then?

Sure.
ā€“ Define verables

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local MapsFolder = ServerStorage:WaitForChild("Maps")
local f = game:GetService("RunService"):IsStudio()

local Status = ReplicatedStorage:WaitForChild("Status")
local reward = 25
local plrs = "Players"
local Players = "plrs"
local GameLength = 70
local MinPlayers = 1 -- Minimum players needed to start the match
local doGameYieldsInStudio = true -- Should yield for stuff like Intermissions in studio


--Game Loop

while true do
	while wait() do

--[[if #game.Players:GetPlayers() >= 2 then

-- code here

end]]
	Status.Value = "Intermission"
	
	if not f or (f and doGameYieldsInStudio) then wait(10) end
	repeat Status.Value = "Waiting for players" wait() until #game.Players:GetPlayers() >= 2 
	
	Status.Value = "Choosing map.."
	
	local plrs = {} 
	for i, player in pairs(game.Players:GetPlayers()) do
		if player then
			table.insert(plrs,player) -- Add each player into plrs 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
	
	--Teleport players to map. 
	
	
	local SpawnPoints = ClonedMap:FindFirstChild("SpawnPoints")
	
	if not SpawnPoints then
		print("No spawn points located in",ChosenMap.Name)
		return
	end
	
	
	
	
	
	local AvailableSpawnPoints = SpawnPoints:GetChildren()
	--teleport them
	for i,plr in ipairs(plrs) do
	  
	if plr.Character and plr.Character:FindFirstChild("HumanoidRootPart") then
	   
	 plr.Character:SetPrimaryPartCFrame(AvailableSpawnPoints[1].CFrame)
	   
	 table.remove(AvailableSpawnPoints,1)
		--give them sword
		local Sword = ServerStorage.Sword:Clone()
		Sword.Parent = plr.Backpack
		
		local GameTag = Instance.new("BoolValue") -- Was BoostValue, unsure what that meant
		GameTag.Name = ("GameTag")
		GameTag.Parent = plr.character
	  else
		plrs[i] = nil
	  end
	end
	
	

	
	 
		--There is no character
		if not player then
			table.remove(plrs,i)
			end
		end
	end
	
	
	Status.Value = "Get ready to play!"
	
	wait(2)
	
	for i = GameLength,0,-1 do
		  for x, player in ipairs(plrs) do
			if player then
				end
				character = player.Character
				
			    if not character or (character:FindFirstChild("Humanoid")) and character.Humanoid.Health == 0 then
        table.remove(plrs,x)
					--left game
					
					end
				else
					if character:FindFirstChild("GameTag") then
						--They are still alive
						
						print(player.Name.."is still in the game!")
					
					else --they are dead
						table.remove(plrs,x)
					   print(player.Name.."Has been removed!")
					end
			end
		
else
				plrs[x] = nil
				--table.remove(plrs,x)
				--print (player.Name.."Has been removed!")
				
			end
		end
		Status.Value = "There are "..i.."Seconds remaining, and "..#plrs.."players left"
		
		if #plrs == 1 then
			--last person standing
			
			Status.Value = "The winner is " ..plrs[1].Name
			plrs[1].leaderstats.Money.Value = plrs [1].leaderstats.Money.Value + reward
			break
		  elseif #plrs == 0 then
			Status.Value= "Nobody won!"
			break
		elseif i == 0 then
			  Status.Value = "Time up!"
			break
			
		end
		wait(1)
		
	end
	
	print ("End of game")
	
	for i, player in pairs(game.Players:GetPlayers()) do
		character = player.character
		if not character then
			--ignore them
		else 
			if character:FindFirstChild("GameTag") then
				character.GameTag:Destroy()
				
			end
			if player.Backpack:FindFirstChild("Sword")then
				player.Backpack.Sword:Destroy()
			end
			--[[if character.Backpack:FindFirstChild("Sword") then -- Would cause errors, there is no Backpack in player
				character.Backpack.Sword:Destroy()
			end]]
			if character:FindFirstChild("Sword") then
				character.Sword:Destroy()
			end
			player:LoadCharacter()
		end
		ClonedMap:Destroy()
	
		wait (2)
		
		Status.Value = "Game Ended!"
		end
	end
end

Unrelated question but why do you have a

while true do
looping(Attempting to loop) a while wait() do

it is looping the codeā€¦ Constantly searching for people who have, died, or left.

Look if you do

while true do
then do
while wait() do
only the while wait() will be executing.

It almost messed up, I will leave thatā€¦ All I really need help with is the ā€œelseā€

Update, this is the whole script.

-- Define verables

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local MapsFolder = ServerStorage:WaitForChild("Maps")
local f = game:GetService("RunService"):IsStudio()

local Status = ReplicatedStorage:WaitForChild("Status")
local reward = 25
local plrs = "Players"
local Players = "plrs"
local GameLength = 70
local MinPlayers = 1 -- Minimum players needed to start the match
local doGameYieldsInStudio = true -- Should yield for stuff like Intermissions in studio


--Game Loop

while true do
	while wait() do

--[[if #game.Players:GetPlayers() >= 2 then

-- code here

end]]
	Status.Value = "Intermission"
	
	if not f or (f and doGameYieldsInStudio) then wait(10) end
	repeat Status.Value = "Waiting for players" wait() until #game.Players:GetPlayers() >= 2 
	
	Status.Value = "Choosing map.."
	
	local plrs = {} 
	for i, player in pairs(game.Players:GetPlayers()) do
		if player then
			table.insert(plrs,player) -- Add each player into plrs 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
	
	--Teleport players to map. 
	
	
	local SpawnPoints = ClonedMap:FindFirstChild("SpawnPoints")
	
	if not SpawnPoints then
		print("No spawn points located in",ChosenMap.Name)
		return
	end
	
	
	
	
	
	local AvailableSpawnPoints = SpawnPoints:GetChildren()
	--teleport them
	for i,plr in ipairs(plrs) do
	  
	if plr.Character and plr.Character:FindFirstChild("HumanoidRootPart") then
	   
	 plr.Character:SetPrimaryPartCFrame(AvailableSpawnPoints[1].CFrame)
	   
	 table.remove(AvailableSpawnPoints,1)
		--give them sword
		local Sword = ServerStorage.Sword:Clone()
		Sword.Parent = plr.Backpack
		
		local GameTag = Instance.new("BoolValue") -- Was BoostValue, unsure what that meant
		GameTag.Name = ("GameTag")
		GameTag.Parent = plr.character
	  else
		plrs[i] = nil
	  end
	end
	
	

	
	 
		--There is no character
		if not player then
			table.remove(plrs,i)
			end
		end
	end
	
	
	Status.Value = "Get ready to play!"
	
	wait(2)
	
	for i = GameLength,0,-1 do
		  for x, player in ipairs(plrs) do
			if player then
			end
		   end
		     end
				character = player.Character
				
			    if not character or (character:FindFirstChild("Humanoid")) and character.Humanoid.Health == 0 then
        table.remove(plrs,x)
					--left game
					
					end
				
					if character:FindFirstChild("GameTag") then
						--They are still alive
						
						print(player.Name.."is still in the game!")
					
					else --they are dead
						table.remove(plrs,x)
					   print(player.Name.."Has been removed!")
					end

		
else
				plrs[x] = nil
				--table.remove(plrs,x)
				--print (player.Name.."Has been removed!")
				
			end
		end
		Status.Value = "There are "..i.."Seconds remaining, and "..#plrs.."players left"
		
		if #plrs == 1 then
			--last person standing
			
			Status.Value = "The winner is " ..plrs[1].Name
			plrs[1].leaderstats.Money.Value = plrs [1].leaderstats.Money.Value + reward
			break
		  elseif #plrs == 0 then
			Status.Value= "Nobody won!"
			break
		elseif i == 0 then
			  Status.Value = "Time up!"
			break
			
		end
		wait(1)
		
	end
	
	print ("End of game")
	
	for i, player in pairs(game.Players:GetPlayers()) do
		character = player.character
		if not character then
			--ignore them
		else 
			if character:FindFirstChild("GameTag") then
				character.GameTag:Destroy()
				
			end
			if player.Backpack:FindFirstChild("Sword")then
				player.Backpack.Sword:Destroy()
			end
			--[[if character.Backpack:FindFirstChild("Sword") then -- Would cause errors, there is no Backpack in player
				character.Backpack.Sword:Destroy()
			end]]
			if character:FindFirstChild("Sword") then
				character.Sword:Destroy()
			end
			player:LoadCharacter()
		end
		ClonedMap:Destroy()
	
		wait (2)
		
		Status.Value = "Game Ended!"
		end
	end
end

What do you want me to do? that would help. :slight_smile:

I feel like this problem has been drawn out a bit much - 29 posts is far too much when the visible issue is fairly simple. It was just a simple question of code organisation where ends and such were being put in the wrong place or error messages werenā€™t being understood.

For the second code, you need to change the operator from = to == (is equal). There are other operators available which you can combine; <, >, ==, >= and <=. Check the Developer Hub for more information on syntax, or the Lua website (specifically either PiL or the Lua Manual).

2 Likes

I think I understand that part, but I do not know where

and @Ugh_Lily What is that?

A plugin to help you organize your code. Itā€™ll format the code for you automatically.
https://gfycat.com/GoodnaturedCommonAndeancondor

perhaps there is a bracket missing.
I only counted five so the statement is not concise.

Where do you get it to fix the scripts, it is not doing it on my end. I canā€™t find that screen that you have.

That means you have an error. Open up Script Analysis for me.

Can you send the link for meā€¦ Thanks!

Usually just look for the red underline to begin with. That typically highlights your source of error; in this case, placing an else statement outside of an if statement and ending another scope too early. I also see a few bad practices in your code.

Your IDE should automatically complete some scopes and statements, as well as indent your code for you, so make sure to use that to your advantage to determine where to place code.

The right questions werenā€™t being asked which may have been part of the reason why this thread got so bloated.

I can provide a fix for you, but a forewarning that Iā€™m on mobile so itā€™s not complete code.

-- Good practice to index services first
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")

-- Next your variables*
local MoneyData = DataStoreService:GetDataStore("MoneyDataStore")
local DefaultCash = 100
--* In the future, you'll want to save all player data in one DataStore or so.
-- Instead of a DataStore for money, make one for data. Save a table to that DataStore with money as an entry.

Players.PlayerAdded:Connect(function (Player)
    -- Create leaderstats and money value like in your original code

 
   Player.CharacterAdded:Connect(Character)
        -- Status and tag destroy here
    end) -- Do not call LoadCharacter unless CharacterAutoLoads is false; set RespawnDelay to 0 instead

    local success, data = pcall(MoneyData.GetAsync, MoneyData, player.UserId)

    if success then
        if data then
            -- Set value of money
        else
            -- Set value of money to default
        end
    else
        -- Call errored, handle DataStore error
    end
end)

That should be about it.

Itā€™s built into Studio.

I think i got that sorted out already, thanks for the help though! :wink: