Trying to get the items in a shop to print it’s name themselves when clicked and found in a module script using these script:
local RS = game:GetService("ReplicatedStorage")
local S = RS.Remotes:WaitForChild("Shop")
local Backpacks = require(RS:WaitForChild("BPacks"))
local SPanel = SGui.ShopPanel
local BPShop = SPanel.BPackShop
local BPItems = BPShop.Items
for _,v in pairs (BPItems:GetChildren()) do
if v:IsA("TextButton") then
v.MouseButton1Click:Connect(function()
local GetPack = v[Backpacks.Packs]
print(GetPack)
end)
end
end
Is the name of the TextButton supposed to align with the name of the “Pack” inside of the Module, such as “Default” or “Small”? I’m trying to get a better understanding of what you’re using the TextButton for inside of the GetPack variable.
In that case, the variable would need to be modified in order to reference a table inside of the Packs table using the name of the TextButton:
for _, item in ipairs(BPItems:GetChildren()) do
if item:IsA("TextButton") then
item.MouseButton1Click:Connect(function()
local packName = item.Name
local GetPack = Backpacks.Packs[packName] -- This will look through the "Packs" table for something with the same name as the button that clicked it
if GetPack then
print(GetPack)
end
end)
end
end