Event ":Once" Being called more then once

hey im doing a inventory system with specific description of every item,
and i used the “:once” event and it works fine when i click 1 item
but when i click 2 it runs the event twice.

local function Open(child,status: "fast" | "slow")
	ItemSelected = child.Name
	local tween = tweenservice:Create(frame,TweenInfo.new(TweenTime,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut),{Position = Positions.framePositionNew})
	

	
	Item.ItemBio.Text = bios[ItemSelected]
	Item.ItemName.Text = ItemSelected
	Item.ItemType.Text = "Item Type: "..types[ItemSelected]



	if types[ItemSelected] == "Equipible" then
		Item["Un/Equip"].AutoButtonColor = true
		if player.Backpack:FindFirstChild(ItemSelected) then -- if the item is found
			Item["Un/Equip"].Text = "UnEquip"
			statusItem("Red")
		else
			Item["Un/Equip"].Text = "Equip"
			statusItem("Green")
		end

		Item["Un/Equip"].MouseButton1Click:Once(function() --HERE
			if player.Backpack:FindFirstChild(ItemSelected) then
				print(ItemSelected.." 1")
				player.Backpack:FindFirstChild(ItemSelected):Destroy()
			else
				print(ItemSelected.." 2")
				rep.Tools:FindFirstChild(ItemSelected):Clone().Parent = player.Backpack
			end
			print(3)
			task.wait(0.1)
			Close(child)
		end)


	else
		Item["Un/Equip"].Text = "UnEquipible"
		Item["Un/Equip"].AutoButtonColor = false
		statusItem("Red")
	end
	opened = true
	if status == "fast" then
		StopViewPortFrame()
		if frame.Visible == true then
			rep.Models:FindFirstChild(ItemSelected).PrimaryPart:Clone().Parent = Item:FindFirstChild("ViewPortFrame")
		end
		Item.Visible = true
	else
		cd = true
		tween:Play()
		task.delay(TweenTime,function()
			if ItemSelected ~= nil and opened == true then
				StopViewPortFrame()
				if frame.Visible == true then
					rep.Models:FindFirstChild(ItemSelected).PrimaryPart:Clone().Parent = Item:FindFirstChild("ViewPortFrame")
				end
				Item.Visible = true
				task.wait(0.2)
				cd = false
			end
		end)
	end 
end

Fixed it by seperating the click event from the function.

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