Getting a nil value for tools

I have a local script in a gui that is supposed to give players some tools (spells) when the gui is clicked. I get the error message: Players.trueblockhead101.PlayerGui.Class Choose.Frame.Fire.ClassClick:7: attempt to call a nil value

local storage = game.ReplicatedStorage
local spell = storage.Spells.Fire


function leftClick()
	local epic = spell:GetChildren()
	local epic2 = epic:Clone()
	epic2.Parent = game.Players.LocalPlayer.Backpack
	script.Parent.Parent.Parent.Enabled = false
end


script.Parent.MouseButton1Click:Connect(leftClick)

spell:GetChildren() gets everything inside of spells.fire

is this what you are trying to achieve?

also instead of enabled, use visible

Its for a screengui so enabled is the only one, And yes im trying to get everything in spells.fire, which are all tools

I don’t think you can really use Clone() on a table of objects. I would parent each child of spell to the player’s backpack individually with a for loop.

for _, child in pairs(epic) do
    local epic2 = child:Clone()
    epic2.Parent = game.Players.LocalPlayer.Backpack
end
2 Likes

You cant clone getchildren, its a tables and you cant clone them

exactly what @Physicism said is correct lol

So like this?

local storage = game.ReplicatedStorage
local spell = storage.Spells.Fire


function leftClick()
	local epic = spell:GetChildren()
	for _, child in pairs(epic) do
		local epic2 = child:Clone()
		epic2.Parent = game.Players.LocalPlayer.Backpack
	end
	script.Parent.Parent.Parent.Enabled = false
end


script.Parent.MouseButton1Click:Connect(leftClick)

Wait i just tested it and it works thanks. I keep forgetting about the whole for i, in pairs stuff, thanks

1 Like

This is correct. Always use this method when trying to parent a group of objects to something else.

1 Like