This value is being called as nil

so i have this tiebreaker system in place for my minigames so that if there are no players left and the game is still running ( to avoid an unbreakable loop ) it can bring them back, but for some reason calls this value as nil

Error:

Flood Escape  -  Server  -  RoundSystem:106
ServerScriptService.RoundSystem:107: attempt to call a nil value  -  Server  -  RoundSystem:107
Stack Begin  -  Studio
Script 'ServerScriptService.RoundSystem', Line 107  -  Studio  -  RoundSystem:107
Stack End  -  Studio

script:

ServerStorage = game:GetService("ServerStorage")
ReplicatedStorage = game:GetService("ReplicatedStorage")
Players = game:GetService("Players")
teams = game:GetService("Teams")
DataStoreService = game:GetService("DataStoreService")
CashDataStore = DataStoreService:GetDataStore("cashDataStore")

Maps = ServerStorage:WaitForChild('Maps'):GetChildren()
RoundStatus = ReplicatedStorage:WaitForChild('RoundStatus')
GameStatus = ReplicatedStorage:WaitForChild("GameStatus")

local Survivors = {}


while wait() do
	if #game.Players:GetPlayers() >= 2 then

		local countdown = 10
		for i = countdown, 0, -1 do
			RoundStatus.Value = "Intermission: "
			GameStatus.Value = i
			wait(1)
		end

		ChosenMap = Maps[math.random(1, #Maps)]:Clone()
		MapName = game.ReplicatedStorage.MapName.Value
		MapName = ChosenMap.Name
		Spawns = ChosenMap:FindFirstChild('Spawns'):GetChildren()

		countdown = 3
		for i = countdown, 1, -1 do
			RoundStatus.Value = ChosenMap.Name.." has been chosen!"
			GameStatus.Value = i + 5
			wait(1)
		end

		countdown = 5
		for i = countdown, 0, -1 do
			ChosenMap.Parent = workspace
			RoundStatus.Value = "Teleporting everyone..."
			GameStatus.Value = i
			wait(1)
		end
		
		local Players = game.Players:GetPlayers()

		for _, Player in ipairs(game.Players:GetPlayers())do
			if Player.Character and Player.Character:WaitForChild('Humanoid') then
				RandomSpawn = Spawns[math.random(1, #Spawns)]
				Player.Character.HumanoidRootPart.CFrame = RandomSpawn.CFrame
				Player.TeamColor = BrickColor.new("Persimmon")
				Player.Character.Humanoid.MaxHealth = 100
				Player.Character.Humanoid.Health = 100
				Player.Character.Humanoid.WalkSpeed = 16
				Survivors[Player] = true
			end
		end

		wait(1)

		countdown = 999999999999999999999999999999999999999999999999999999999999999999
		for i = countdown, 0, -1 do
			RoundStatus.Value = "Game is currently in progress.."

			local Survivor = game.Teams.Playing
			if #Survivor:GetPlayers() == 1 then
				for i,v in pairs(game.Teams["Playing"]:GetPlayers()) do
					v.leaderstats.Cash.Value += 1

					for _, Player in pairs(game.Players:GetChildren())do
						if Player.Character and Player.Character:FindFirstChild('Humanoid') then
							Player.Character.Humanoid.Health = 0
						end
					end

					countdown = 3
					for i = countdown, 1, -1 do
						ChosenMap:Destroy()
						RoundStatus.Value = "Round Over!"
						GameStatus.Value = i + 5
						local winner = game.ReplicatedStorage.Winner
						winner.Value = v.Name
						wait(1)
					end

					countdown = 5
					for i = countdown, 0, -1 do
						ChosenMap:Destroy()
						RoundStatus.Value = v.Name.. " has won!"
						GameStatus.Value = i
						winner = game.ReplicatedStorage.Winner
						winner.Value = v.Name
						wait(1)
					end
					wait(5)
					winner.Value = "Nobody!"

				end
				break
			end
			
			while countdown > 0 and #Survivor:GetPlayers() == 0 do
				
				ChosenMap:Destroy()
				
				print(MapName)
				ChosenMap = Maps:FindFirstChild(MapName):Clone()
				ChosenMap.Parent = game.Workspace
				
				for _, Player in ipairs(game.Players:GetPlayers())do
					if Player.Character and Player.Character:WaitForChild('Humanoid') then
						RandomSpawn = Spawns[math.random(1, #Spawns)]
						Player.Character.HumanoidRootPart.CFrame = RandomSpawn.CFrame
						Player.TeamColor = BrickColor.new("Persimmon")
						Player.Character.Humanoid.MaxHealth = 100
						Player.Character.Humanoid.Health = 100
						Player.Character.Humanoid.WalkSpeed = 16
						Survivors[Player] = true
					end
				end
			end

			wait(1)
		end

	else
		local dots = "..."

		repeat
			for i = 1,3 do
				RoundStatus.Value = "Waiting For Players"..string.sub(dots, 1, i)
				wait(1)
			end
		until #game.Players:GetPlayers() >= 2
	end

end

What is line 107, the line erroring? Can you please show that because I am having a hard time counting the lines up.

ChosenMap = Maps:FindFirstChild(MapName):Clone()

inside:
while countdown > 0 and #Survivor:GetPlayers() == 0 do

The error seems to be this line:

ChosenMap = Maps:FindFirstChild(MapName):Clone()

if I counted correctly :smiley:
what does the line before it print? Does it print the map name correctly?

Print the MapName. Also, the way you are doing the countdown thing is inefficient. Just make it repeat the code inside until the amount of players left is 1.

yes it prints the name of the map correctly, thats why it says ā€œFlood Escapeā€ in the output

i already printed the mapname directly before cloning the map and prints correctly

Okay but you should change that for loop up. Anyways, if the map name is found inside of the maps folder as well then perhaps its the variable itself.

also, its inefficient because i want it to be able to be quickly changed in case i want a countdown later on

this is my serverstorage:
image

Oh alright, just making sure you knew there was an easier option. The code is weirdly indented on my screen so I am trying to read it. Lemme see.

You can’t use FindFirstChild on Maps because it’s an array.

1 Like

what should i use instead of WaitForChild()

Its because you have defined:

Maps = ServerStorage:WaitForChild('Maps'):GetChildren()

but the line with the error:

ChosenMap = Maps:FindFirstChild(MapName):Clone()

Maps is a table of the contents of the folder Maps so you can’t call FindFirstChild ont it

Also, if you are storing your maps in server storage then you gotta change workspace to that as well.

I’m not sure how this will affect the rest of your code, but you would need to remove :GetChildren() to reference the container by itself.

getchildren() in Maps = ServerStorage:WaitForChild(ā€˜Maps’):GetChildren()? because it works everywhere except the tiebreaker part

GetChildren() is fine but you can’t use FindFirstChild() on the result of GetChildren()

local MapsLocation=ServerStorage:WaitForChild("Maps")
local Maps=MapsLocation:GetChildren()

Now you can use

MapsLocation:FindFirstChild("MapName")
1 Like

now it works for the first time and then gives this error after:

ServerScriptService.RoundSystem:110: attempt to index nil with 'Parent'  -  Server  -  RoundSystem:110
Stack Begin  -  Studio
Script 'ServerScriptService.RoundSystem', Line 110  -  Studio  -  RoundSystem:110
Stack End  -  Studio

as far as i know, that error is saying that chosenmap is nil. i never set that variable to nil at any point of the script