Hello so I have the problem that my script has the error parent property locked and also it doesn’t change the limit counter if I have the BackPack accesoire 
Script is in the StarterCharacterScripts Service!
error:
The Parent property of Players.SpiderLeander1.Backpack.Grenade is locked
code:
local limit = 5
local limit2 = 10
function updateTools()
local backpack = game.Players.LocalPlayer:WaitForChild("Backpack")
local char = script.Parent
local tools = {}
for i, child in pairs(char:GetChildren()) do
if child:IsA("Tool") then table.insert(tools, child) end
end
for i, tool in pairs(backpack:GetChildren()) do
table.insert(tools, tool)
end
for i, tool in pairs(tools) do
if i > limit2 and char:FindFirstChild("BackPack") then
tool:Destroy()
else
if i > limit then
tool:Destroy()
end
end
end
end
local backpack = game.Players.LocalPlayer:WaitForChild("Backpack")
backpack.DescendantAdded:Connect(updateTools)
backpack.DescendantRemoving:Connect(updateTools)
workspace.DescendantAdded:Connect(updateTools)
workspace.DescendantRemoving:Connect(updateTools)
1 Like
Something unexpectedly tried to set the parent of CrowBar to NULL while trying to set the parent of CrowBar. Current parent is Backpack
1 Like
Try using Debris, I did some quick testing and it worked for me!
(Your code modified to use Debris service)
local limit = 5
local limit2 = 10
local Debris = game:GetService("Debris")
function updateTools()
local backpack = game.Players.LocalPlayer:WaitForChild("Backpack")
local char = script.Parent
local tools = {}
for i, child in pairs(char:GetChildren()) do
if child:IsA("Tool") then table.insert(tools, child) end
end
for i, tool in pairs(backpack:GetChildren()) do
table.insert(tools, tool)
end
for i, tool in pairs(tools) do
if i > limit2 and char:FindFirstChild("BackPack") then
Debris:AddItem(tool, 0)
else
if i > limit then
Debris:AddItem(tool, 0)
end
end
end
end
local backpack = game.Players.LocalPlayer:WaitForChild("Backpack")
backpack.DescendantAdded:Connect(updateTools)
backpack.DescendantRemoving:Connect(updateTools)
workspace.DescendantAdded:Connect(updateTools)
workspace.DescendantRemoving:Connect(updateTools)
1 Like
Didn’t worked for me now if I drop something and want to get something new it doesn’t work
1 Like