Attempt to index nil with 'Clone'

Ive put a sword in the map, i called a function to clone it. but it returns attempt to index nil with ‘Clone’
Does anyone know how to fix this? i cant get it to work

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

A more proper way to do this is to just use a for i,v in pairs loop

for i,v in pairs(workspace.Ingame:GetChildren())-- v is the child of the map Ingame and it will keep looping for every single child of the map, the number of times it will loop is i(index) and the child is v(variable) 
-- eg if your child of the map is a tree,a sword and a car, it will loop one time and either the tree,sword or car is selected as v,if a tree is "selected" , v would be the tree,then i would be 1. after that, only the sword and car is left, sa the car was selected, v would be the car, i would be 2. then all thats left to be looped is the sword, v would be the sword, i would be 3. So in total, it looped 3 times and gone through every single child of the map.


end

So in your case, you have 2 ways to solve it, one is just

workspace.Ingame:FindFirstChildWhichIsA("Tool"):Clone().Parent = --whatever you want

or by using for index,variable(table) loop

for i,v in pairs(workspace.Ingame:GetChildren())
-- looping through every single child of the map
if v:IsA("Tool") then -- if v class is a tool 
v:Clone().Parent = whatever -- clone it
end
end

Still returns the same error unfortunately

show me ur workspace.Ingame descendants or children cuz nil means it aint there

image

does taht look like a tool to you? thats a model ;-; change “Tool” to “Model”
a tool is the one with the hammer icon

Im not that stupid, its meant to clone a sword thats inside the map. so did i just make a typo

“map:FindFirstChildWhichIsA(“Tool”):Clone()”

it clearly says that it has to find the tool inside the map, not the ingame. im not that stupid for seeing a model for a tool.

is the sword already in the game? or is it like after some time it will randomly spawn or smt

Its inside the map, as soon as the round starts. players are supposed to spawn with a sword. the players are in the ingame folder, the tool aka sword is in the map.

if you want the players to have the sword once the round starts why not put it in replicated storage? this way it would have never been nil
if you for some reason want the sword to be in the map for decoration or whatsoever
then put 1 in the map and 1 in replicated storage, then clone the one in replicated storage, this way it wont disappear and wont be nil

1 Like

you dont have to that way, u just have to make a loop in game.Players then clone it in player.Backpack

for i, player in pairs(game.Players:GetChildren()) do
if not player.Character then continue end
local clone = map:FindFirstChildWhichIsA(“Tool”):Clone()
clone.Parent = player.Backpack
end

how about now?

Made a folder with all the weapons in replicatedstorage, will just clone them from there from now on. Thanks for the idea.

3 Likes