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)
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
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