Event fires 36 times instead of once

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

image

1 Like

I don’t really understand the specific issue, it appears that you have the remote event in a loop which is possibly why it fires 36 times?

add “break” below the remote if you want it to execute the loop once only.

Oh my god right now i realised i didn’t remove that test loop I added previously.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.