Attempt to index nil with 'Clone'?

I want when it teleports u to the arena,a sword to appear into ur inventory.
But this error appeared on my output:

" ServerScriptService.Script:42: attempt to index nil with ‘Clone’ "

The code where the error is:

local children = workspace.Ingame:GetChildren()
		for i = 1,#children do
			map:FindFirstChildWhichIsA("Tool"):Clone().Parent = children[i] -- problem/error
		end

Here’s the full code"

local status = game.ReplicatedStorage.Status
local maps = game.ReplicatedStorage.Maps:GetChildren()

while true do
	for i = 1,10 do
		status.Value = "Intermission: "..10-i
		wait(1)
	end
	
	local rand = math.random(1, #maps)
	
	local map = maps[rand]:Clone()
	map.Parent = workspace
	
	status.Value = "We'll be playing "..map.Name.."!"
	local players = game.Players:GetChildren()
	wait(4)
	for i = 1,#players do
		local spawnLocation = workspace.Teleports:FindFirstChild(map.Name)
		players[i].Character:MoveTo(workspace.Teleports:FindFirstChild(map.Name).Position)
		players[i].Character.Parent = workspace.Ingame
		
	end
	
	local roundLenght = 0
	local CanWin = true
	local RoundType = ""
	
	if map:FindFirstChild("Obby") then
		RoundType = "Obby"
		map.EndPart.Touched:Connect(function(hit)
			if hit.Parent:FindFirstChild("Humanoid") then
				CanWin = false
				status.Value = hit.Parent.Name.." has won!"
			end
		end)
	elseif map:FindFirstChild("Sword") then
		RoundType = "Sword"
		
		local children = workspace.Ingame:GetChildren()
		for i = 1,#children do
			map:FindFirstChildWhichIsA("Tool"):Clone().Parent = children[i]
		end
		
		map:FindFirstChildWhichIsA("Tool"):Destroy()
	end
	
	if map.Name == "the Lava Race" then
		roundLenght = 60
	end
	
	if map.Name == "a Sword Fight" then
		roundLenght = 120
	end
	
	repeat
		roundLenght = roundLenght -1
		status.Value = "Time Left: "..roundLenght
		wait(1)
	until roundLenght == 0 or CanWin == false or #workspace.Ingame:GetChildren() == 0 or (#workspace.Ingame:GetChildren() == 1 and RoundType == "Sword")
	
	if #workspace.Ingame:GetChildren() == 1 and RoundType == "Sword" then
		status.Value = workspace.Ingame:FindFirstChildWhichIsA("Model").Name.."has won!"
	end	
	
	if roundLenght == 0 then
		status.Value = "Time's up!"
	end
	
	wait(3)
	
map:Destroy()
end
1 Like

I believe that it is not finding the Tool

1 Like

To fix this, Put the sword in ServerStorage then get a referance to it. Then you can clone it and set the clone’s parent to the players starter pack. When the round is over or they die destroy the clone.

1 Like

Doesn’t work. :confused:
I don’t know why, do you know another way?

I might be able to, It will take time. Also can i see the error.

1 Like

Uh, yeah sure.

Right there: DevForumCapture

oh it still cant get the sword

1 Like

do you have a referance to the sword?

1 Like

It’s the classic Roblox sword, find it in the Toolbox.

Ok, I bet you could do

local Sword = game.ServerStorage.Sword -- change Sword to the swords name

this will get a referance to the sword if it is in ServerStorage

1 Like

Also you could make a fail safe

if map:FindFirstChildWhichIsA("Tool") then
map:FindFirstChildWhichIsA("Tool"):Clone().Parent = children[i]
print("Succes")
else
print("Could not find Sword")
end

try this insted of “map:FindFirstChildWhichIsA(“Tool”):Clone().Parent = children[i]” if the print line “Could not find Sword” works then you need to find the sword

1 Like

It is exactly the same error. I don’t know what to do anymore.

Wich one did you try? So then i can figure it out better.

1 Like

Dont give up. Where did you put the Sword. StarterPack? ServerStorage? ReplicatedStorage?

1 Like

wait, actually, there’s not that error anymore.
But it’s showing this error instead: attempt to index nil with ‘Destroy’ :roll_eyes:

code where is the problem/error:

map:FindFirstChildWhichIsA("Tool"):Destroy()

I did in ReplicatedStoarge. Because in ServerStoarge wasn’t working.

Ok, I think you need to find the specific player then get his/her sword.

1 Like

Also im glad we/you fixed the giving

1 Like

Did you fix it? if so what did you do to fix it?

1 Like

Well, i din’t actually fix it, i forgot to tell you that,there are no more errors, but there’s no sword into my inventory…