Problem with disconnecting functions

  1. What do you want to achieve?
    I have a had a bug on my game that I dont know how to fix, the problem I’m having is this.
    When my shop starts then a for loop goes through all the items in there starting a controller for each one.

  2. What is the issue? Include screenshots / videos if possible!
    The issue is that. For one item it works fine but, when you start clicking different items without doing anything (buy or equip) then, once the user finally buy one item all of those who were clicked before will get bought too

(Dont mind “ESTOY AQUI” those are different things) Test and Test2 are items, different items but once I click the Buy button after clicking like 10 times each one it buys both items like 10 times

https://i.gyazo.com/2595e44edee63c24db987eba4abf251b.mp4

Video of the problem happening

  1. What solutions have you tried so far?

I have already tried to disconnect the function after a different button has been clicked trying to make it independent of each other but it didn’t go well

Here is the code from the shop controller

local function SHOP_CONTROLLER(child)
	local BUTTON_FRAME_PU = child:FindFirstChild("Item")
		
	local OBJECT3D = child:FindFirstChild("3DIMG")
	--Cargar todo
	local PART_RECREATE = OBJECT3D.MeshPart
	PART_RECREATE.Parent = OBJECT3D
	PART_RECREATE.Position = PART_RECREATE.FACING_VALUE.Value
	PART_RECREATE.Rotation = PART_RECREATE.FACING_VALUE.Value
	local NEW_CAMERA = Instance.new("Camera", OBJECT3D)
	
	OBJECT3D.CurrentCamera = NEW_CAMERA
	NEW_CAMERA.CFrame = CFrame.new(Vector3.new(-1,1,-3), PART_RECREATE.Position)
	
	OBJECT3D.MouseEnter:Connect(function()
		local theInfo = {
			CFrame = PART_RECREATE.CFrame*CFrame.Angles(0, math.rad(-45), 0)
		}
		
		Animate3DGUI(theInfo, PART_RECREATE)
	end)
	
	OBJECT3D.MouseLeave:Connect(function()
		local theInfo = {
			CFrame = CFrame.new(PART_RECREATE.FACING_VALUE.Value)
		}
		
		Animate3DGUI(theInfo, PART_RECREATE)
	end)
	local TEST
	BUTTON_FRAME_PU.MouseButton1Click:Connect(function()
		local INFO_IT = GET_ITEM_INFO(child.Parent.Name, child.Name)
		local SHOP_ITEM_INFO = SECTION_CONTENTS["INFO"]
		
		--
		if INFO_IT == nil then
			
		else
			SHOP_ITEM_INFO.Level.Text = "Level: " .. INFO_IT["LVL"]
			SHOP_ITEM_INFO.Price.Text = FORMATING(INFO_IT["PRICE"]).."$"
			SHOP_ITEM_INFO.Name_.Text = child.Name
			SHOP_ITEM_INFO.Description.Text = INFO_IT["DESCRIPTION"]
		end
		
		--Item 3D
		local Item3D = SHOP_ITEM_INFO.Item3D
		local getRests = Item3D:FindFirstChild("MeshPart")
		local getRests_Camera = Item3D:FindFirstChild("Camera")
		if getRests then
			getRests:Destroy()
			--Habia restos antiguos asi que los elimino
		end
		
		if getRests_Camera then
			getRests_Camera:Destroy()
		end
		
		local NEW_PART_RECREATE = PART_RECREATE:Clone()
		NEW_PART_RECREATE.Position = NEW_PART_RECREATE.FACING_VALUE.Value
		NEW_PART_RECREATE.Rotation = NEW_PART_RECREATE.FACING_VALUE.Value
		NEW_PART_RECREATE.Parent = Item3D
		
		local NEW_CAMERA_ITEM = Instance.new("Camera", Item3D)
		Item3D.CurrentCamera = NEW_CAMERA_ITEM 
		
		NEW_CAMERA_ITEM.CFrame = CFrame.new(Vector3.new(-1,1,-3), NEW_PART_RECREATE.Position)
		
		--Ahora debemos saber si el usuario posee el objeto, en caso afirmativo entonces lo que haremos será emitir el mensaje de equipar en vez de comprar
		
		if child.Parent.Name == "PowerUpFrame" then
			--Es una tool, comprobamos el folder de las tools
			local ToolFolder = DATA_OF_USER.Inventory.Tools.Tool
			local FIND_THE_ITEM_IN_INV = ToolFolder:FindFirstChild(child.Name)
			if FIND_THE_ITEM_IN_INV then
				--El objeto existe
				if FIND_THE_ITEM_IN_INV.Value == false then
					--No lo tiene asi que lo compramos
					BUY_ITSELF(SHOP_ITEM_INFO, child)
				else
					--Si lo tiene comprado
					EQUIP_TOOL(child.Parent.Name, child, DATA_OF_USER.Inventory, SHOP_ITEM_INFO)
				end
			else
				ANNOUNCE("For some unknown reason this item is not avaible")
			end
		elseif child.Parent.Name == "VanityFrame" then
			--Es una vanity
			local ToolFolder = DATA_OF_USER.Inventory.Tools.Vanity
			local FIND_THE_ITEM_IN_INV = ToolFolder:FindFirstChild(child.Name)
			if FIND_THE_ITEM_IN_INV then
				--El objeto existe
				if FIND_THE_ITEM_IN_INV.Value == false then
					--No lo tiene asi que lo compramos
					BUY_ITSELF(SHOP_ITEM_INFO, child)
				else
					EQUIP_TOOL(child.Parent.Name, child, DATA_OF_USER.Inventory, SHOP_ITEM_INFO)
				end
			else
				ANNOUNCE("For some unknown reason this item is not avaible")
			end
		end
	end)
end

for i,v in pairs(SECTION_CONTENTS["PU"]:GetChildren())do
	if v:IsA("UIGridLayout")then
		
	else
		SHOP_CONTROLLER(v)
	end
end
1 Like