TextButton.Activated event only firing once

Ok, maybe try:

CreditsContainer.TextButton.MouseButton1Click:Connect(function()
	print("click")
	if not IS_CREDIT_SHOP_OPEN then
		BuyCreditsContainer:TweenPosition(UDim2.new(0.163, 0,0.929, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quint, .7, true)
		IS_CREDIT_SHOP_OPEN = true
		print("is open")
	elseif IS_CREDIT_SHOP_OPEN 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)

I’m on a relatively blank game with a small chunk of terrain. Don’t think lag has anything to do with it. If anything the effect would be delayed, not stopped from happening.

Tried it even though I already explained multiple times this was the original approach I took. click is only printing once.

Alright, maybe move the line the code that changes IS_CREDIT_SHOP_OPEN to the first line after the if statement, e.g.

if IS_CREDIT_SHOP_OPEN == false then
 IS_CREDIT_SHOP_OPEN = true

This is going to be a little weird, but can you replace the function with

while wait(5) do
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
1 Like

It’s opening and closing. Kind of confused about this lol.

It is better to use an event instead of a loop.

By the way, I would recommend reading this about while wait() do.

2 Likes

I was just seeing if it was the code inside that was breaking it or something with the button and event. Read the etire convo to figure out where we’re at

That at least rules out the possibility of TweenPosition being an issue. Not that I ever thought it was anyways. Progress I suppose.

Someone just gave me the idea of commenting everything out and leaving the print("click) in, and it does look like the event is getting fired multiple times so there’s something wrong with my logic that’s preventing it from firing multiple times.

Yeah, so I don’t think this is an error with the function, I think you will need to check the client side explorer and all. Class just resumed so I must leave. If it’s still an issue, add me on discord jrdonat#0262 and i’ll try and fix it in person

1 Like

it looks ;like the “elseif” is incorrectly indented? is it just the Website because when i copy/paste your code into studio its not incorrectly indented? if it is the actual indention of the code then thats the issue probably

The position of the indentation doesn’t affect the conditional statement.

just try this:

CreditsContainer.TextButton.Activated:Connect(function()
	if IS_CREDIT_SHOP_OPEN then
		BuyCreditsContainer:TweenPosition(UDim2.new(-0.26, 0,0.929, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, .7, true)
		IS_CREDIT_SHOP_OPEN = false
	else  
		BuyCreditsContainer:TweenPosition(UDim2.new(0.163, 0,0.929, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quint, .7, true)
		IS_CREDIT_SHOP_OPEN = true
	end	
end)

My original test with this involved me using else instead of elseif. It didn’t work.

why are you using HeatBeat:Wait() ? isnt that pretty unneccesary? also can you upload your entire code?

I feel like I’ve said “I’ve already said this” and “again” like 40 times in this post so I’m just going to start quoting responses I have previously provided.

alright if it doesnt make a dfifference then you should remove it because it will just reduce efficieny, also can you still upload all your code? mb mb i see it

i took the liberty of recreating everything (respectively with the information ive been given)
the red GUI is the BuyCreditsContainer
the white frame is the CreditsContainer
and the text button is the text button
Workspace:
image
code:


Click0:

Click1: (dashes off screen)

click2: comes back ect ect. is there anything else happening to the GUI and whats the workspace structure

did the print statments work correctly when it wasnt working for you?