local plr = game.Players.LocalPlayer
local replicatedstorage = game:GetService("ReplicatedStorage")
local pack = plr.Backpack:GetChildren()
script.Parent.MouseButton1Click:Connect(function()
if plr.Backpack:FindFirstChild("RedSword") or plr.StarterGear:FindFirstChild("RedSword") then
print ( plr.Name .. "already has this item")
else
if plr.leaderstats.Wins.Value>5 or #pack>=11 then
pack:ClearAllChildren()
replicatedstorage.RedSword:Clone().Parent = plr.Backpack
replicatedstorage.RedSword:Clone().Parrent = plr.StarterGear
else
print ( plr.Name .. "needs more money to buy this item")
end
end
end)
The shop works, giving the sword and all, but I dont want the inventory to cloud up, so if the pack is more than 11, it will clear all children and THEN give the one sword.
error: attempt to call method 'ClearAllChildren' (a nil value)
it works fine without me trying to empty it out.

1 comment
it's because
packis a table of all the children in backpack,packis not the backpack itself