TextButton.Activated event only firing once

I’m currently working on a GUI for in-game currency and ran into an issue while trying to create a popout for buying said in-game currency.

At the moment the popout does “open” but doesn’t close.

Current Result

https://i.gyazo.com/84e280d6bb2c8b14f5aa168838262f51.mp4

Output only prints “click” and “is open” once. Help would be appreciated.

CreditsContainer.TextButton.Activated:Connect(function()
	print"click"
	if IS_CREDIT_SHOP_OPEN == false then
		BuyCreditsContainer:TweenPosition(UDim2.new(0.163, 0,0.929, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quint, .7, true)
		RunService.Heartbeat:Wait()
		IS_CREDIT_SHOP_OPEN = true
		print"is open"
	elseif IS_CREDIT_SHOP_OPEN == true then
			print"should be closing"
			BuyCreditsContainer:TweenPosition(UDim2.new(-0.26, 0,0.929, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, .7, true)
			RunService.Heartbeat:Wait()
			IS_CREDIT_SHOP_OPEN = false
		end	
end)

Try using

CreditsContainer.TextButton.MouseButton1Down:Connect(function()

Try text button.mousebutton1click

.Activated is relatively the same thing. With that being said I tried using MouseButton1Up/Down and it was only firing once too.

Can I see more of the script? Some of the variables?

It’s probably getting stuck on :Wait then

That is what I am thinking. When the heartbeat waits, it waits every heartbeat.

CreditsContainer.TextButton.Activated:Connect(function()
	print("click")
    print(IS_CREDIT_SHOP_OPEN)
	if IS_CREDIT_SHOP_OPEN == false then
		BuyCreditsContainer:TweenPosition(UDim2.new(0.163, 0,0.929, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quint, .7, true)
		wait(0.7)
		IS_CREDIT_SHOP_OPEN = true
		print("is open")
	elseif IS_CREDIT_SHOP_OPEN == true then
		print("should be closing")
		BuyCreditsContainer:TweenPosition(UDim2.new(-0.26, 0,0.929, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, .7, true)
		wait(0.7)
		IS_CREDIT_SHOP_OPEN = false
	end	
end)

It’s the equivalent of using wait(), I added this after the version without wait() wasn’t working because I assumed the variable was being set to true or false too fast.

As for the rest of the variables:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")

local Network = ReplicatedStorage:WaitForChild("Network")
local Remotes = Network:WaitForChild("Remotes")

local Player = Players.LocalPlayer
local Data = Player:WaitForChild("Data")

local HUD = script.Parent

-- Container Components
local BuyCreditsContainer = HUD:WaitForChild("BuyCreditsContainer")
local CreditsContainer = HUD:WaitForChild("CreditsContainer")
local ShopContainer = HUD:WaitForChild("ShopContainer")

-- Button Components
local MusicButton = HUD:WaitForChild("MusicButton")
local ShopButton = HUD:WaitForChild("ShopButton")

-- States
local IS_CREDIT_SHOP_OPEN = false

Data.Credits:GetPropertyChangedSignal("Value"):Connect(function()
	CreditsContainer.CreditsLabel.Text = Data.Credits.Value .. " Credits"
end)

CreditsContainer.TextButton.Activated:Connect(function()
	print"click"
	if IS_CREDIT_SHOP_OPEN == false then
		BuyCreditsContainer:TweenPosition(UDim2.new(0.163, 0,0.929, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quint, .7, true)
		RunService.Heartbeat:Wait()
		IS_CREDIT_SHOP_OPEN = true
		print"is open"
	elseif IS_CREDIT_SHOP_OPEN == true then
			print"should be closing"
			BuyCreditsContainer:TweenPosition(UDim2.new(-0.26, 0,0.929, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, .7, true)
			RunService.Heartbeat:Wait()
			IS_CREDIT_SHOP_OPEN = false
		end	
end)

I assume there’s no errors? I would just use print statements to debug

There’s no errors. I did add prints to see what portions of the script aren’t being ran. As the original post states it appears that the event itself is only being fired once.

Are you by chance moving the button?

I would probably try using

CreditsContainer.TextButton.MouseButton1Click:Connect(function()
   --Code
end

also in your code where it prints I would use print(“…”) instead of print"…"
and also why do you need to use RunService.Heartbeat?

Output from the prints you added in this reply:

click  -  Client  -  LocalScript:30
false  -  Client  -  LocalScript:31
is open  -  Client  -  LocalScript:36

Already replied to this – using print"" doesn’t affect anything and is ultimately down to preference.

As for MouseButton1Click I also explained that I was still running into the same problem.

And when you click again, no response. I would make sure the button is still there or the script isn’t freezing somewhere else (Or getting moved or deleted)

I visually confirmed that the button is not being moved and is still visible with nothing overlaying the button. (Checked using explorer in-game after making the frame visible.)

Ok, maybe take out the RunService.Heartbeat bit and just make it so that

elseif IS_CREDIT_SHOP_OPEN == true then
		print"should be closing"
		BuyCreditsContainer:TweenPosition(UDim2.new(-0.26, 0,0.929, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, .7, true)
		IS_CREDIT_SHOP_OPEN = false
	end	
end)

Again, I also explained this in an earlier reply. I added RunService.Heartbeat:Wait() after thinking the variable was being changed too quickly. I’ve tried it without using wait() and it’s still the same problem.

Well. The script itself looks fine. I think it’s an issue elsewhere.
EDIT: I’ve had similar issues with GUIs not running well on large or laggy games. However i’m not sure what your case is.