1. What do you want to achieve?
So im making a game where you have wood but its a tool. The tool has an attribute in it called “quantity”. I am trying to make it so that you can stack the wood together. In this script i tried to get all the tools in the backpack with a for loop and add all the amounts and create a clone of the tool with the amounts added up and then deleting all of the wood which was used to make the stack
2. What is the issue?
And before you look at the script, YES I KNOW ITS PROBABLY BAD AND LAZY. i just dont know how to approach this as i am a beginner scripter. so basically when ever the script finds a tool it adds the amount and clones it but then it deletes the clone so you never end up with the stacked item.
local gui = script.Parent.Parent
local player = gui.Parent.Parent
local button = script.Parent
button.Activated:Connect(function()
local stackAmount = 0
for i, v in pairs(player.Backpack:GetChildren()) do
if v:GetAttribute("quantity") then
stackAmount += v:GetAttribute("quantity")
task.wait(0.1)
v:Destroy()
local newItem = v:Clone()
newItem.Parent = player.Backpack
newItem:SetAttribute("quantity", stackAmount)
end
end
end)
and i dont want to just put a folder in the player and put all the material values in there because i want to be able to share resources with other people as well
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Idk i just gave up. this problem is pretty niche (and stupid) so i couldnt find anything to help me