[NEED ANSWER]Connection to Event Disconnecting?

For my simulator game, I’ve tried to made a shop system. (I’ve never made something like this before)
Basically, you start with item 1 and you cant get item 3 until you get item 2, etc.
I’ve made a buy function and a (broken) equip function, but the buttons dont seem to be firing.

The thing is, everything is working fine except for when I buy. It buys it and then after that the connection to the buttons being clicked gets disconnected.

I do not understand why this is happening and any help would be appreciated.
I have not found any answers on dev hub or searching.

Here are my scripts:
ShopModule.lua (ModuleScript in game > ReplicatedStorage > Assets > Modules)

-- made by recanman
local sm = {}
local db

function sm:Initialize(frame)
	for _, child in ipairs(frame.List.ItemStorage:GetChildren()) do
		if (child:IsA("TextButton")) then
			child:Destroy()
		end
	end
	
	frame.InfoFrame.Visible = false
	for _, child in ipairs(game.ReplicatedStorage.Assets.Tasers:GetChildren()) do
		local template = game.ReplicatedStorage.Assets.Other.Template:Clone()
		template.Name = child.Name
		template.PetFrame.PetDisplay.PetName.Text = child.Name
		template.Parent = frame.List.ItemStorage
		
		local vpfTaser = game.ReplicatedStorage.Assets.Tasers[child.Name]:Clone()
		local model = Instance.new("Model")
		template.PetFrame.PetDisplay:FindFirstChildOfClass("Model"):Destroy()
		
		model.Parent = template.PetFrame.PetDisplay
		for _, child in ipairs(vpfTaser:GetChildren()) do
			child.Parent = model
		end
		
		model.PrimaryPart = model.Handle
		model.TaserScript:Destroy()
		model.Parent = template.PetFrame.PetDisplay
		model:SetPrimaryPartCFrame(CFrame.new(-0.348, 0.695, -85.803))
		model:SetPrimaryPartCFrame(model:GetPrimaryPartCFrame() * CFrame.Angles(math.rad(0), math.rad(40), math.rad(45)))
		template.LayoutOrder = child.Settings.Order.Value
		
		local isUnlocked = game.ReplicatedStorage.Assets.Events.DataStoreTaserCheckEvent:InvokeServer()
		
		if (isUnlocked + 1 >= template.LayoutOrder) then
			child.Settings.Locked.Value = false
		else
			child.Settings.Locked.Value = true
		end
		
		if (child.Settings.Locked.Value == true) then
			template.Locked.Visible = true
			template.PetFrame.PetDisplay.Visible = false
		else
			template.Locked.Visible = false
			template.PetFrame.PetDisplay.Visible = true
		end
	end
end

function sm:ShowInfoFrame(child, plr, infoFrame)
	print(child.Name)
	--if (child)
	infoFrame.Visible = false
	infoFrame.Equipped.Visible = false
	infoFrame.Equip.Visible = false
	infoFrame.BuyNow.Visible = false
	
	infoFrame.PetDisplay.PetName.Text = child.Name
	infoFrame.Stats.Cost.Text = game.ReplicatedStorage.Assets.Tasers[child.Name].Settings.Cost.Value
	infoFrame.Stats.CoinsPerClick.Text = game.ReplicatedStorage.Assets.Tasers[child.Name].Settings.CoinsPerClick.Value
	
	local vpfTaser = game.ReplicatedStorage.Assets.Tasers[child.Name]:Clone()
	local model = Instance.new("Model")
	infoFrame.PetDisplay:FindFirstChildOfClass("Model"):Destroy()
	
	model.Parent = infoFrame.PetDisplay
	
	for _, child in ipairs(vpfTaser:GetChildren()) do
		child.Parent = model
	end
		
	model.PrimaryPart = model.Handle
	model.TaserScript:Destroy()
	model.Parent = infoFrame.PetDisplay
	model:SetPrimaryPartCFrame(CFrame.new(-0.348, 0.695, -85.803))
	model:SetPrimaryPartCFrame(model:GetPrimaryPartCFrame() * CFrame.Angles(math.rad(0), math.rad(40), math.rad(45)))
	
	local currentTaser = plr.CurrentTaser.Value
	local isUnlocked = game.ReplicatedStorage.Assets.Events.DataStoreTaserCheckEvent:InvokeServer()
	
	if (child.Name == currentTaser) then
		infoFrame.Equipped.Visible = true
	end
	
	if (isUnlocked >= child.LayoutOrder) then
		infoFrame.Equip.Visible = true
	elseif (isUnlocked + 1 == child.LayoutOrder) then
		infoFrame.BuyNow.Visible = true
		infoFrame.BuyNow.MouseButton1Click:Connect(function()
			if (db == false and plr.leaderstats.Coins.Value >= game.ReplicatedStorage.Assets.Tasers[child.Name].Settings.Cost.Value) then
				db = true
				game.ReplicatedStorage.Assets.Events.TaserBuyEvent:FireServer(child.Name)
				plr.CurrentTaser.Value = child.Name
				plr.Character.Humanoid:UnequipTools()
				plr.Backpack:ClearAllChildren()
				game.ReplicatedStorage.Assets.Tasers[child.Name]:Clone().Parent = plr.Backpack
				sm:Initialize(infoFrame.Parent)
			elseif (plr.leaderstats.Coins.Value < game.ReplicatedStorage.Assets.Tasers[child.Name].Settings.Cost.Value) then
				local tween = game:GetService("TweenService"):Create(infoFrame.BuyNow.AvailableIn, TweenInfo.new(0.2, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 2, true, 0), {TextColor3 = Color3.new(1, 0, 0)})
				tween:Play()
			end
			infoFrame.Equip.MouseButton1Click:Connect(function() -- broken, fix
				db = true
				print(child.Name)
				plr.CurrentTaser.Value = child.Name
				plr.Character.Humanoid:UnequipTools()
				plr.Backpack:ClearAllChildren()
				game.ReplicatedStorage.Assets.Tasers[child.Name]:Clone().Parent = plr.Backpack
				sm:Initialize(infoFrame.Parent)
			end)
				db = false
		end)
	end
	
	wait()
	infoFrame.Visible = true
end

return sm

TaserBuy.lua (script located in game > ServerScriptService > CoreGameScripts)

-- made by recanman
local ds2 = require(1936396537) -- ds2 module

game.ReplicatedStorage.Assets.Events.TaserBuyEvent.OnServerEvent:Connect(function(plr, taser)
	local taserDs = ds2("Tasers", plr)
	local currentTaser = game.ReplicatedStorage.Assets.Events.DataStoreTaserCheckEvent.InformHandler:Invoke(plr)
	
	if (currentTaser + 1 == game.ReplicatedStorage.Assets.Tasers[taser].Settings.Order.Value) then
		plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value - game.ReplicatedStorage.Assets.Tasers[taser].Settings.Cost.Value
		taserDs:Increment(1)
	end
end)

ShopHandler.lua (located in game > StarterGui > Main > MainFrame > ShopFrame2 > Frame > List)

-- made by recanman
local sm = require(game.ReplicatedStorage.Assets.Modules.ShopModule)
script.Parent:WaitForChild("ItemStorage")

sm:Initialize(script.Parent.Parent)

for _, child in ipairs(script.Parent.ItemStorage:GetChildren()) do
	if (child:IsA("TextButton") and child.Locked.Visible ~= true) then
		child.MouseButton1Click:Connect(function()
			sm:ShowInfoFrame(child, game.Players.LocalPlayer, script.Parent.Parent.InfoFrame)
		end)
	end
end

Also I have to click the buy button 2 times for it to fire I don’t know why.
Why is no one answering this…? 100 views

BUMP, its been 8 hours with no answer.

Still need help, its been 10 hours?!!

I skimmed through the code and I don’t see anything noticeably wrong. There might be something not wrong with the code itself but something that is stopping it from running again.

I have had many times with no answers so I get where you are coming from, but it is frowned upon to bump.

Probably because people might read it and can’t figure out the answer.
I wouldn’t rely on the DevForum, Maybe get some developer friends and join some developer discord servers.

This might relate to why it won’t work a second time, make sure you run print statements throughout the code.

Also are there any errors in the output?

No errors, I would have fixed them if they occurred. The thing is I need to bump because im releasing this in a few days

Ok so maybe run some print statements throughout the code. I would think it would have to be something after you have fired the remote function.

I also skimmed through, and haven’t found any significant mistakes. Then again, I’m on mobile currently. I’ll take a better look when I get on PC. Are these the only scripts related to this functionality?

1 Like

Yes, that is correct. There are the only scripts related.

Have you found any mistakes yet?

Which remote function exactly?

UPDATE:
I did not do anything, now no events are connecting at all?!

I need help as soon as possible.

I am not able to resume development without this. Please

I have run some print statements, here are my results.
The for loop runs and identifies which items are locked and which aren’t.
Then, it doesn’t connect the MouseButton1Click event for some reason and when I put a print statement there and click it nothing happens.

Maybe another gui is blocking the button? Has happened to me before.

No it is not, I can confirm.
It is not blocking it.

One week, without an answer. I will pay robux for someone to answer it if necessary.