I am making a trading GUI, im at the part now where I script the clicking the items(Inventory) and adding them to the trading frame and likewise clicking the items from the trading frame and adding it to the inventory frame, Is this the most efficient way to do it:
Issue with code: Adding the item works and removing it the first time, the second time: clicking the item(Trading Frame) doesn’t remove it and add it to the inventory frame, I believe this issue is because I use a "For Loop", as it doesnt loop through the scrolling frame again to add a MouseButton1Down connection to that cloned item.
Q: Should I add more for loops(for it to re-loop and add a MouseButton1Down connection to the newly cloned item) to fix this issue, or should I do something else?
code:
------------- Function:Add
local function addItemFrame(item)
local vB = item:Clone()
local template = game.ReplicatedStorage.ItemFrame:Clone()
template.Name = "Item"
template.Text = item.Text
template.Parent = mainPlayerFrame
local furtherPush = template:Clone()
furtherPush.Parent = enemyScreenGUi.TradingFrame.EnemyBox.ScrollingFrame
return template, vB
end
-------------- Adding Items on Frame -- Main Player
for i,v in pairs(plrInvScrollingFrame:GetChildren()) do
if v:IsA("TextButton") then
v.MouseButton1Down:Connect(function()
local template, vB = addItemFrame(v)
template.MouseButton1Down:Connect(function()
template:Destroy()
local item = vB
item.Parent = plrInvScrollingFrame
item.MouseButton1Down:Connect(function()
print("Clicked")
local template, vB = addItemFrame(item)
item:Destroy()
end)
end)
v:Destroy()
end)
end
end