Hello again, I was wondering what is wrong with my script.
This script should check backpack of the player who triggered the function.
If found 3 tools with the same name, do nothing.
The tool is in the right Parent and folder, but I think it’s something wrong on the table.
Any help is appreciate.
local toolsininventory = {}
local storage = game.ServerStorage:FindFirstChild("Restock system")
script.Parent.Triggered:Connect(function(player)
if storage then
print("Found!")
local x = storage:FindFirstChild("Tools")
local possiblevalue = player.Backpack:FindFirstChild(script.Parent.Parent.Name)
table.insert(toolsininventory,possiblevalue)
if #toolsininventory <= 3 then
for i,v in pairs(x:GetChildren()) do
if v.Name == script.Parent.Parent.Name then
local clone = v:Clone()
clone.Parent = player.Backpack
end
end
else
table.clear(toolsininventory)
end
else
error("No folder ServerStorage was found, can't assign tool to player.")
end
end)