Script Skipping If Statement

I have a round based game. Currently i have 2 GameModes and it selects one by random. When it selects the Free-For-All, it Finishing in One Second or Less. On the Death Match One, it does it like its suppose to.

main game code
local AvailableGameModes = GameModesFolder:GetChildren()
	local ChosenGameMode = AvailableGameModes[math.random(1,#AvailableGameModes)]
	Status.Value = ChosenGameMode.Name
	if ChosenGameMode.Value == 'Free-For-All' then
		
	
		 local plrs = {}
	        	
	        	for i, player in pairs (game.Players:GetPlayers()) do
			  	if (not player.IntroTag.Value) and (not player.AFK.Value) then 
        			table.insert(plrs,player)--Add each players into plrs table
					print(player)
					print(#plrs)
			     else
					warn(player, 'was not Inserted - AFK or Intro.')
 					print(#plrs)
								
			end 
		end


		wait(1)
	
	local AvailableMaps = MapsFolder:GetChildren()
	local ChosenMap = AvailableMaps[math.random(1,#AvailableMaps)]
	
	Status.Value = "Choosing a Map..."
	wait(3)
	
	Status.Value = ChosenMap.Name.." Chosen"
	wait(1)	
	local ClonedMap = ChosenMap:Clone()
	ClonedMap.Parent = workspace
	
		--					   --
		-- Selecting GameMode  --
		--					   --
	Status.Value = 'Choosing a GameMode!'
	wait(3)
	
	
	--[[      |				|
			  |				|
		 Teleport Players to Map
			  |				|
			  |				|
								
							--]]
	wait(1)
	workspace.LobbyMusic.Intermission:Pause()
	local SpawnPoints = ClonedMap:FindFirstChild("SpawnPoints")
	
	if not SpawnPoints then 	
		error("SpawnPoints not Found!")
	end
	
	pcall(function()
	local AvailableSpawnPoints = SpawnPoints:GetChildren()
	
	for i, player in pairs(plrs) do
		if player then
			character = player.Character
			
			if character then 
				--Teleport Them
				character:FindFirstChild("HumanoidRootPart").CFrame = AvailableSpawnPoints[1].CFrame + Vector3.new(0,8,0)
				table.remove(AvailableSpawnPoints,1)
				
				
				--Give them a sword
				local equipped = game.ServerStorage.PlayerData[player.Name].Equipped
				
				if equipped.Value ~= "" then
					local weapon = game.ServerStorage.Items[equipped.Value]:Clone()
					weapon.Parent = player.Backpack
				else
					local Sword = ServerStorage.Sword:Clone()
					Sword.Parent = player.Backpack
				end
				game.Workspace:FindFirstChildOfClass("Player")
							
				local GameTag = Instance.new("BoolValue")
				GameTag.Name = "GameTag"
				GameTag.Parent = player.Character
			else
				--There is no Character 
				if not player then 
					table.remove(plrs,i)
				end
			end
		end
	end	
end)
	
	Status.Value = "Get Ready to Play!"
	
	wait(3)
	
	for i = GameLength,0,-1 do 
		
		for x, player in pairs(plrs) do
			if player then
				
				character = player.Character
				
				if not character then 
					--left the game
					table.remove(plrs,x)
				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)
					end
				end
			else 
				table.remove(plrs,x)
				print(player.Name.." has been Removed!")
				
			end
		end
		
		Status.Value = "Free-For-All|Time:"..i.."|Players:"..#plrs..""
		
		if #plrs == 1 then 
			Status.Value = "Yeet"
			wait(0.01)
			Status.Value = "The Winner is "..plrs[1].Name
			matchEnd:Play()
			plrs[1].leaderstats.Wins.Value = plrs[1].leaderstats.Wins.Value + win
			plrs[1].leaderstats.Buxs.Value = plrs[1].leaderstats.Buxs.Value + reward
			plrs[1].leaderstats.XP.Value = plrs[1].leaderstats.XP.Value + xp
			wait(2)
			--plrs[1].XP.Value = plrs[1].XP.Value + xp
			break
		elseif #plrs == 0 then 
			Status.Value = "Nobody won!"
			wait(3)
			break
		elseif i == 0 then 
			Status.Value  = "Time's up!"
			timeUp:Play()
			wait(3)
			break
	
		end
		game.Workspace.Sounds.MatchCompleted:Pause()
		wait(1)
	end
	print("End of Game")
	
	wait(1)
	
	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
			for _, tool in pairs(player.Backpack:GetChildren()) do
				if tool:FindFirstChild("Price") then
					tool:Remove()
				end
			end
			for _, tool in pairs(character:GetChildren()) do 
				if tool:FindFirstChild("Price") then
					tool:Remove()
				end
			end
		end
		
		player:LoadCharacter()
	end
	
	ClonedMap:Remove()
	wait(1)
	
	--[[      |				|
			  |				|
		 Fading Out Music and Ending the Loop.
			  |				|
			  |				|
								
							--]]
		
	Status.Value = "Game ended"
	pcall(function()
	wait(5)
	for i = 0,7 do
		
			workspace.GameMusic:FindFirstChildOfClass("Sound").Volume = workspace.GameMusic:FindFirstChildOfClass("Sound").Volume - 0.10
			wait(1)
		end
	end)
	workspace.Sounds.TimesUp:Pause()
	wait(0.8)
	workspace.LobbyMusic.Intermission:Resume()
		elseif ChosenGameMode.Name == 'Team DeathMatch' then
		wait(3)
		local Team_One = {}
		
		local Team_Two = {}

function shuffle(arr) --This was stolen from another DevForum post. I cannot remember where I got it from.
    local arrCopy = {unpack(arr)}

    for i = 1, #arr do
        arr[i] = table.remove(arrCopy, math.random(#arrCopy))
    end
    return arr
end

local plrsTDM = {}
for i, player in pairs(game.Players:GetPlayers()) do --Insert current players to table
    table.insert(plrsTDM,player)
	wait()
	print(player.Name)
end

local randomPlayers = shuffle(plrsTDM) --Randomize players table

for i = 1, math.ceil(#randomPlayers/2) do --Take half of the random players and put them into team 1
    table.insert(Team_One, randomPlayers[i])
	print(randomPlayers[i],"is in Team One")
	randomPlayers[i]:FindFirstChild('Team').Value = 'Red'
    table.remove(randomPlayers, i)
	
end

for i, v in pairs(randomPlayers) do --Put the rest of the players into team 2
    table.insert(Team_Two, v)
	print(randomPlayers[i], "is in Team Two")
	randomPlayers[i]:FindFirstChild('Team').Value = 'Blue'
end
randomPlayers = {} --Reset table
	end
end
1 Like

Could you post the full code, it could be something with your variables or other things, the indentation is very off, and it’s hard to tell what is the issue.

Also that function you stole was from me. You can have it lol

1 Like

Could you elaborate more?

Based on what I can see, you lack at least one “end” for if statement , does’t it error?

What is the value of your GameLength variable? I would bet that it is not what you think it is.

local GameLength = 90

Hmm what other possible things could be going on?

No it does not error, it just skips the Free-For-All mode when its selected in 1 second or less.

What Function? The Team DeathMatch one?
Heres the rest of the code:

--					--
		-- Getting Services --
		--					--
		
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local ServerStorage = game:GetService("ServerStorage")

local StarterGui = game:GetService("StarterGui")

		--					   --
		-- Making Code Cleaner --
		--					   --

local MinPlayersTilStart = #game.Players:GetPlayers() >= 1

local GameLength = 90

local win = 1

local reward = 50

local xp = 45

local tiereward = 5		
		--					                   --
		-- Getting Folders and Everything Else --
		--					                   --
		
local MapsFolder = ServerStorage:WaitForChild("Maps")

local GameModesFolder = ServerStorage:WaitForChild("GameModes")

local Status = ReplicatedStorage:WaitForChild("Status")

local gameModeGui = StarterGui.GameMode

local gameModeScript = StarterGui.GameMode.Handler
		
		--					   				--
		-- Sounds (should find a better way) --
		--					  				 --

local Player = game.Players.LocalPlayer

local s = Instance.new("Sound")
 
local  winner = Instance.new("Sound")
local  matchEnd = Instance.new("Sound")

local timeUp = Instance.new("Sound")

local plrs5 = Instance.new("Sound")
local plrs4 = Instance.new("Sound")
local plrs3 = Instance.new("Sound")
local plrs2 = Instance.new("Sound")
local plrs1 = Instance.new("Sound")
			
		--[[  |				|
			  |				|
			  |--Game Loop--|
			  |				|
			  |				|
								
							--]]

while true do 
gameModeScript.Disabled = false

Status.Value = "Waiting for 1 more player.."

--[[plrs5.Name = "5 Left"
plrs5.SoundId = "rbxassetid://2668565546"
plrs5.Volume = 1
plrs5.Archivable = true
plrs5.Parent = workspace.Sounds


plrs4.Name = "4 Left"
plrs4.SoundId = "rbxassetid://2668565344"
plrs4.Volume = 1
plrs4.Archivable = true
plrs4.Parent = workspace.Sounds


plrs3.Name = "3 Left"
plrs3.SoundId = "rbxassetid://2668565196"
plrs3.Volume = 1
plrs3.Archivable = true
plrs3.Parent = workspace.Sounds


plrs2.Name = "2 Left"
plrs2.SoundId = "rbxassetid://2668565050"
plrs2.Volume = 1
plrs2.Archivable = true
plrs2.Parent = workspace.Sounds 
   --]]

s.Name = "Intermission"
	s.SoundId = "rbxassetid://1841979451"
s.Volume = 0.8
s.Looped = true
s.archivable = true


s.Parent = game.Workspace.LobbyMusic

timeUp.Name = "TimesUp"
timeUp.SoundId = "rbxassetid://795701916"
timeUp.Volume = 0.5
timeUp.TimePosition = 1
timeUp.Looped = false
timeUp.archivable = true

timeUp.Parent = game.Workspace.Sounds

matchEnd.Name = "MatchCompleted"
matchEnd.SoundId = "rbxassetid://2956696056"
matchEnd.Volume = 3
matchEnd.Looped = false
matchEnd.Archivable = true

matchEnd.Parent = game.Workspace.Sounds
s:Play()

--[[      	  |				|
			  |				|
		 If There are 2 or more Players it does this.
			  |				|
			  |				|
								
							--]]

	repeat wait() until #game.Players:GetPlayers() >= 1
	Status.Value = "Intermission"
	
		for i = 13, 0, -1 do
   	 Status.Value = "(" .. i  .. ")"
    	wait(1)
	end

On the Team Deathmatch if statement, you wrote
elseif ChosenGameMode.Name == 'Team DeathMatch' then
while on the Free-For-All statement, you wrote
if ChosenGameMode.Value == 'Free-For-All' then

You probably made a typo by checking for the ChosenGameMode.Value instead of the ChosenGameMode.Name.

The Free-For-All if statement should actually look like this:
if ChosenGameMode.Name == 'Free-For-All' then

4 Likes

Thank you! it now works like i wanted it to.

1 Like