The function triggers 1 more every time it fires

function addAuraToInventory(player : Player, aura)
	print("done")
	for index,slot in pairs(player.PlayerGui.MainGui.Values.Inventory:GetChildren()) do
		if slot:IsA("StringValue") then
			if slot.Value == "Empty" then
				slot.Value = aura
				local inventorygui = player.PlayerGui.MainGui.Inventory
				inventorygui.InventoryFrame[slot.Name].Text = aura
				break
			end
		end
	end
end

The function triggers 1 more every time it fires, its really annoying, can anyone help

If you show us where you call the function

1 Like

(its inside randomizerarity function)

	player.PlayerGui.MainGui.RollFrame.EquipButton.MouseButton1Click:Connect(function()
        addAuraToInventory(player, player.PlayerGui.MainGui.Values.LastRolledAura.Value)
		replaceaura(player,player.PlayerGui.MainGui.Values.LastRolledAura.Value)
		player.PlayerGui.MainGui.SpinButton.Visible = true
		player.Values.AuraType.Value = player.PlayerGui.MainGui.Values.LastRolledAura.Value
		player.PlayerGui.MainGui.Values.LastRolledAuraReturnable.Value = false
		refreshTag(player)


	end)
1 Like

Take it out. Every time randomizerarity is called it connects a new MouseButton1Click Event. The MouseButton1Click event should be in the outermost part of the script (meaning it is not in any other functions)

2 Likes

Thanks! i used a remote event to fire from local script to fix it

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