hi, so I have a shop system in game and I’m trying to add armors in to the game.
The issue is upon pressing the button in player UI the event fires 36 times instead of one
Note: UI Reset on respawn is disabled
Does anyone have any idea why would this be happening?
Part of my code
for armorName, prize in pairs(configArmor) do
local newFrame = script.ArmorItem:Clone()
newFrame:WaitForChild("ItemName").Text = armorName
newFrame.Name = armorName
newFrame:WaitForChild("TeamValue").Value = configArmor[armorName][2].TeamColor
if configArmor[armorName][1] == "0" then
newFrame.ItemPrize.Text = "0"
else
newFrame.ItemPrize.Text = configArmor[armorName][1]
end
newFrame.Visible = false
newFrame.Parent = script.Parent.Armor_Frame.Armor
print("Acces to armor denied")
end
plr.CharacterAdded:Connect(function()
local x = script.Parent.Armor_Frame.Armor:GetChildren()
for _, itemArmor in pairs(x) do
if itemArmor:IsA("Frame") and plr.Team.TeamColor == itemArmor.TeamValue.Value then
itemArmor.Visible = true
print("Acces to armor granted")
elseif itemArmor:IsA("Frame") then
itemArmor.Visible = false
end
end
end)
for i, frame in pairs(script.Parent.Armor_Frame.Armor:GetChildren()) do
for a, secondFrame in pairs(frame:GetChildren()) do
if secondFrame:IsA("TextButton") then
secondFrame.MouseButton1Click:Connect(function()
local y = secondFrame.Parent:GetChildren()
print(y)
local armor = secondFrame.Parent.ItemName.Text
local armorPrize = secondFrame.Parent.ItemPrize.Text
if armor and armorPrize then
for u, MaybyArmor in pairs(plr.Character:GetChildren()) do
if MaybyArmor:HasTag("Armor") then
MaybyArmor:Destroy()
end
print("Button clicked")
ShopEvent:FireServer(armor, armorPrize, false, "ARMOR")
end
end
end)
end
end
end