How do I check if either GUIs are clicked?

This is related to this topic here: How to check if any of the buttons are pressed in a GUI

(Please click on the link)

On there he said he resolved the issue, but never said how. I’m trying to make a dialogue with options and I don’t want to take up many lines for an unspecified amount of options, which are in a for loop.

Thank you in advance :slight_smile:

script.Parent.MouseButton1Click:Connect(function()
   print("clicked")
end)

Should work. Please note that MouseButton1Click does not return a parameter. Put this script inside of the UI’s textbutton.

1 Like

But there are multiple buttons.

1 Like

Make variables for them all and seperate functions or loop all of the variables and when you click them, perform the action if they are supposed to perform the same action.

1 Like

Instead of multiple variables, I have a table/array containing them.

1 Like

Find the button thru table.find() or a loop from the table then. Oh, wait. Just loop the table and when the buttons are clicked perform the function if you want to perform the same function. (only if u want all buttons doing the same)

1 Like

And if they’re aren’t the same? Like, you have the options goodbye and continue speaking?

1 Like

Then perform additional checks for example a name, etc and perform a seperate function.

1 Like

Like this?

local optionClicked

for _, v in pairs(options) do
      v.MouseButton1Up:Wait()

      optionClicked = v

      break
end

if optionClicked:FindFirstChild('ContinueDialogue') then
      -- Continue dialogue
end
1 Like

Try it, not entirely sure as I don’t know your table system. Print like a simple yes on the “stuff”

1 Like

Oof, It doesn’t work. At least not the way I want it to.

Hmm, what is the issue, any errors? Actually I have an idea:

  • you make a loop of all the buttons in the frame
  • once it is checked, perform checks to the name and if it matches perform a function() (just so it doesnt get messy)

Could work.

First few tries I had errors. I fixed them, but now it only does the function with only one button.

local optionClicked
local options = script.Parent:GetChildren()

while wait() do
	for _, v in pairs(options) do
		if v ~= script then
			v.MouseButton1Up:Wait()
			
			print('YES')
		
			optionClicked = v
			
			break
		end
		
		break
	end
end	

if optionClicked:FindFirstChild('ContinueDialogue') then
	print("This doesn't print :(")
end

OH WAIT

Ok nvm

1 Like

Check my idea above, do you have Discord? I can help you with this, I know what you are want from the script. Did you try that script with other buttons too?

Isn’t that basically my code?

Just filling in this reply – don’t pay attention to this

Nope.

for _,part in pairs(script.Parent.Frame:GetChildren()) do
	if part:IsA('TextButton') then
		part.MouseButton1Click:Connect(function()
			--perform checks etc and then call their functions
		end)
	end
end
5 Likes

Thank you so much! God bless. This will definitely help :slight_smile:

No problem, if you need more help you can DM me.

1 Like