Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

can anyone can fix this error it say: attempt to call a nil value?

This is code:

local MapsFolder = game.ReplicatedStorage:WaitForChild("Maps")
local status = game.ReplicatedStorage:WaitForChild("Status")

while true do
 status.Value = "Intermission 15"
 local interTime = 15
 repeat wait()
  wait(1)
  interTime = interTime - 1
  status.Value = "Intermission "..interTime
 until interTime <= 0
 wait(1)
 status.Value = "Selecting a map"
 
 local mapId = math.random(1,#MapsFolder:GetChildren())
 local map = MapsFolder:FindFirstChild("Map"..mapId)
 
 wait(1)
 if map then
  status.Value = "Map has been chosen"
  
  local mapName = map:FindFirstChild("MapName")
  if mapName then
   status.Value = "The map is: "..mapName.Value
  else
   status.Value = "The map doesn't have a name"
  end
  wait(1)
  status.Value = "Loading map..."
  
  local newMap
  newMap = map:Clone()
  newMap.Parent = workspace
  newMap.Name = "Map"
  
  wait(2)
  
  status.Value = "Teleporting players..."
  
     local player = 0
     if newMap:FindFirstChild("PlayerSpawns") then
      for i,v in pairs(game.Players:GetPlayers()) do
   local character = workspace:FindFirstChild(v.Name)
   if character then
    local rootPart = character:FindFirstChild("HumanoidRootPart")
    if rootPart then
     local spawnId = math.random(1,#newMap.PlayerSpawns:GetChildren())
        local spawnObj = newMap.PlayerSpawns:FindFirstChild("Spawn"..spawnId)
    
        if spawnObj then
	      player = player + 1
        rootPart.Position = spawnObj.Position
        end
    end
   end
  end
  wait(2)
  status.Value = "The round is starting!"
  wait(2)
  local wave = 1
  local zombies = 0

  repeat wait()
	 status.Value = "Wave ".. wave.."!"
	wait(2)
	
	local waveFolder = game.ReplicatedStorage:WaitForChild("Waves"):FindFirstChild("Waves".. wave)
	if waveFolder then
		for i, v in pairs(waveFolder:GetChildern()) do
			local clone = v:Clone()
			
			local rootPart = clone:FindFirstChildren("HumanoidRootPart")
			if rootPart then
				clone.Parent = workspace
				
				local spawnsObj = map:FindFirstChild("ZombieSpawns")
				if spawnsObj then
					local spawnChild = spawnsObj:GetChildern()
					
					local spawnPos = spawnChild[math.random(1, #spawnChild)]
					
					if spawnPos:IsA("BasePart") then
						rootPart.CFrame = spawnPos.Cframe
						zombies = zombies + 1
					end
				end
			else
			clone:Destory()
			end
		end
	else
		for i = 1,math.random(wave - 1, wave) do
			local zFolder = game.ReplicatedStorage:GetChildren("Zombies")
			local zombie = zFolder:GetChildern()[math.random(1,#zFolder:GetChildern())]:Clone()
			
			local rootPart = zombie:FindFirstChildren("HumanoidRootPart")
			if rootPart then
				local posses = map:FindFirstChild("ZombieSpawns")
			if posses then
   				local pos = posses:GetChildren()[math.random(1, #posses:GetChildren())]
                if pos:IsA("BasePart") then
	            rootPart.CFrame = pos.CFrame
	            zombies = zombie + 1
                 end
             end
         end
      end
   end
       repeat wait() until zombies <= 0

       wave = wave + 1
       until player <= 0 or wave == 100
 
  else
  status.Value = "Map doesn't have spawns! Can't load"
     end
 else
  status.Value = "Failed to find a map"
 end 
 
 if workspace:FindFirstChild("Map") then
  workspace.Map:Destroy()
 end
 
 wait(2)
end

3 comments

0

which line?

0

Line 94

0

You misspelled Children twice on line 94. Made the same mistake.

3 answers

You put

zFolder:GetChildern()

instead of

zFolder:GetChildren()

1 comment

0

it say again attempt to call a nil value

At line 94 (and some others line) u mispelled :GetChildren to :GetChildern(), changed it in this script:

local MapsFolder = game.ReplicatedStorage:WaitForChild("Maps")
local status = game.ReplicatedStorage:WaitForChild("Status")

while true do
 status.Value = "Intermission 15"
 local interTime = 15
 repeat wait()
  wait(1)
  interTime = interTime - 1
  status.Value = "Intermission "..interTime
 until interTime <= 0
 wait(1)
 status.Value = "Selecting a map"

 local mapId = math.random(1,#MapsFolder:GetChildren())
 local map = MapsFolder:FindFirstChild("Map"..mapId)

 wait(1)
 if map then
  status.Value = "Map has been chosen"

  local mapName = map:FindFirstChild("MapName")
  if mapName then
   status.Value = "The map is: "..mapName.Value
  else
   status.Value = "The map doesn't have a name"
  end
  wait(1)
  status.Value = "Loading map..."

  local newMap
  newMap = map:Clone()
  newMap.Parent = workspace
  newMap.Name = "Map"

  wait(2)

  status.Value = "Teleporting players..."

     local player = 0
     if newMap:FindFirstChild("PlayerSpawns") then
      for i,v in pairs(game.Players:GetPlayers()) do
   local character = workspace:FindFirstChild(v.Name)
   if character then
    local rootPart = character:FindFirstChild("HumanoidRootPart")
    if rootPart then
     local spawnId = math.random(1,#newMap.PlayerSpawns:GetChildren())
        local spawnObj = newMap.PlayerSpawns:FindFirstChild("Spawn"..spawnId)

        if spawnObj then
          player = player + 1
        rootPart.Position = spawnObj.Position
        end
    end
   end
  end
  wait(2)
  status.Value = "The round is starting!"
  wait(2)
  local wave = 1
  local zombies = 0

  repeat wait()
     status.Value = "Wave ".. wave.."!"
    wait(2)

    local waveFolder = game.ReplicatedStorage:WaitForChild("Waves"):FindFirstChild("Waves".. wave)
    if waveFolder then
        for i, v in pairs(waveFolder:GetChildren()) do
            local clone = v:Clone()

            local rootPart = clone:FindFirstChildren("HumanoidRootPart")
            if rootPart then
                clone.Parent = workspace

                local spawnsObj = map:FindFirstChild("ZombieSpawns")
                if spawnsObj then
                    local spawnChild = spawnsObj:GetChildren()

                    local spawnPos = spawnChild[math.random(1, #spawnChild)]

                    if spawnPos:IsA("BasePart") then
                        rootPart.CFrame = spawnPos.Cframe
                        zombies = zombies + 1
                    end
                end
            else
            clone:Destory()
            end
        end
    else
        for i = 1,math.random(wave - 1, wave) do
            local zFolder = game.ReplicatedStorage:GetChildren("Zombies")
            local zombie = zFolder:GetChildren()[math.random(1,#zFolder:GetChildren())]:Clone()

            local rootPart = zombie:FindFirstChildren("HumanoidRootPart")
            if rootPart then
                local posses = map:FindFirstChild("ZombieSpawns")
            if posses then
                local pos = posses:GetChildren()[math.random(1, #posses:GetChildren())]
                if pos:IsA("BasePart") then
                rootPart.CFrame = pos.CFrame
                zombies = zombie + 1
                 end
             end
         end
      end
   end
       repeat wait() until zombies <= 0

       wave = wave + 1
       until player <= 0 or wave == 100

  else
  status.Value = "Map doesn't have spawns! Can't load"
     end
 else
  status.Value = "Failed to find a map"
 end 

 if workspace:FindFirstChild("Map") then
  workspace.Map:Destroy()
 end

 wait(2)
end

1 comment

0

it say again attempt to call a nil value

At line 94. You did:

local zFolder = game.ReplicatedStorage:GetChildren("Zombies")
local zombie = zFolder:GetChildern()

What's the "Zombies" inside the :GetChildren()? I'm pretty sure you meant to do wait for child. Try this script:

local MapsFolder = game.ReplicatedStorage:WaitForChild("Maps")
local status = game.ReplicatedStorage:WaitForChild("Status")

while true do
 status.Value = "Intermission 15"
 local interTime = 15
 repeat wait()
  wait(1)
  interTime = interTime - 1
  status.Value = "Intermission "..interTime
 until interTime <= 0
 wait(1)
 status.Value = "Selecting a map"

 local mapId = math.random(1,#MapsFolder:GetChildren())
 local map = MapsFolder:FindFirstChild("Map"..mapId)

 wait(1)
 if map then
  status.Value = "Map has been chosen"

  local mapName = map:FindFirstChild("MapName")
  if mapName then
   status.Value = "The map is: "..mapName.Value
  else
   status.Value = "The map doesn't have a name"
  end
  wait(1)
  status.Value = "Loading map..."

  local newMap
  newMap = map:Clone()
  newMap.Parent = workspace
  newMap.Name = "Map"

  wait(2)

  status.Value = "Teleporting players..."

     local player = 0
     if newMap:FindFirstChild("PlayerSpawns") then
      for i,v in pairs(game.Players:GetPlayers()) do
   local character = workspace:FindFirstChild(v.Name)
   if character then
    local rootPart = character:FindFirstChild("HumanoidRootPart")
    if rootPart then
     local spawnId = math.random(1,#newMap.PlayerSpawns:GetChildren())
        local spawnObj = newMap.PlayerSpawns:FindFirstChild("Spawn"..spawnId)

        if spawnObj then
          player = player + 1
        rootPart.Position = spawnObj.Position
        end
    end
   end
  end
  wait(2)
  status.Value = "The round is starting!"
  wait(2)
  local wave = 1
  local zombies = 0

  repeat wait()
     status.Value = "Wave ".. wave.."!"
    wait(2)

    local waveFolder = game.ReplicatedStorage:WaitForChild("Waves"):FindFirstChild("Waves".. wave)
    if waveFolder then
        for i, v in pairs(waveFolder:GetChildern()) do
            local clone = v:Clone()

            local rootPart = clone:FindFirstChildren("HumanoidRootPart")
            if rootPart then
                clone.Parent = workspace

                local spawnsObj = map:FindFirstChild("ZombieSpawns")
                if spawnsObj then
                    local spawnChild = spawnsObj:GetChildern()

                    local spawnPos = spawnChild[math.random(1, #spawnChild)]

                    if spawnPos:IsA("BasePart") then
                        rootPart.CFrame = spawnPos.Cframe
                        zombies = zombies + 1
                    end
                end
            else
            clone:Destory()
            end
        end
    else
        for i = 1,math.random(wave - 1, wave) do
            local zFolder = game.ReplicatedStorage:WaitForChild("Zombies")
            local zombie = zFolder:GetChildern()[math.random(1,#zFolder:GetChildern())]:Clone()

            local rootPart = zombie:FindFirstChildren("HumanoidRootPart")
            if rootPart then
                local posses = map:FindFirstChild("ZombieSpawns")
            if posses then
                local pos = posses:GetChildren()[math.random(1, #posses:GetChildren())]
                if pos:IsA("BasePart") then
                rootPart.CFrame = pos.CFrame
                zombies = zombie + 1
                 end
             end
         end
      end
   end
       repeat wait() until zombies <= 0

       wave = wave + 1
       until player <= 0 or wave == 100

  else
  status.Value = "Map doesn't have spawns! Can't load"
     end
 else
  status.Value = "Failed to find a map"
 end 

 if workspace:FindFirstChild("Map") then
  workspace.Map:Destroy()
 end

 wait(2)
end

If it was helpful please vote up!

1 comment

0

it say GetChildern is not a valid member of Folder 

This discussion is preserved as it was. New answers, comments, and votes are closed.