Why is my function not running when I click on a button in my gui?

I am trying to make a script where I use a table to find the buttons inside of a frame. If its name is not “Close” and it is a TextButton, then it should run the function SENDSHOPNAME. I, however, do not get any output that I should be getting when I press a button that is in the table. Can someone help out? I have tried before to integrate what is in SENDSHOPNAME into the table function, but it did not work either (same results).

function SENDSHOPNAME(BNAME)
	BNAME.MouseButton1Down:Connect(function()
		print("connected")
		local PRICE = string.gsub(BNAME,"PromptBuy","")
		PROMPT(PRICE)
		print(PRICE)
	end)
end

for i, ACTIVATE in pairs(Client.ShopFrame:GetChildren()) do
	if ACTIVATE:IsA("TextButton") and ACTIVATE.Name == not "Close" then
		SENDSHOPNAME(ACTIVATE)
	end
end

edit: solved, I should of used
ACTIVATE.Name =~ "Close"
instead of
ACTIVATE.Name == not "Close"

2 Likes

Full uppercase for naming things is concerning.

I found some guidelines for you, if you are interested.
https://roblox.github.io/lua-style-guide/

It wasn’t related to that, but I did it on purpose. It’s my only code that is in full uppercase for unrelated reasons

Could you mark your post as solved if it was solved? This will help others not to try and reply.

I’m going to leave a quick comment on your if statement conditions provided in your post.


  • ACTIVATE.Name == not "Close"

What happens here, is that you’re going to be comparing a string value to a Boolean. Which no matter what, will always return false, as you can’t compare the two values with each-other. This is because by typing not "Close" you’re essentially typing ‘false’. You can confirm yourself if you do print(not "Close") into the command bar, which prints out false. As the string value won’t be equal to the boolean value, the condition is false and the code within the if statement will not run.

This could’ve easily been fixed without changing it to ~=, simply by changing the following line from:
if ACTIVATE:IsA("TextButton") and ACTIVATE.Name == not "Close" then
to:
if ACTIVATE:IsA("TextButton") and not (ACTIVATE.Name == "Close") then

What happens now is that if the ‘Activate’ instance’s name isn’t ‘Close’ then that statement is false. By appending ‘not’ before it, it negates the bool, or simply, makes it the opposite of what it originally was.
I.E: true becomes false, and vice-versa.

1 Like