Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make a function that fires when two buttons are selected?

I'm making a GUI that is supposed to let you "breed" two animal AI, but I don't know how to tell the script to occur only when the two boxes (already created and named) are selected and the "Breed" button is clicked. I've tried to look at some other scripts to see how this is done for selecting one button, but I can't figure it out, especially for two separate buttons. I included my script below, and I am aware that it is incomplete and messy currently. Also some of the variables I have here may not make sense yet because I need them for stuff I'm gonna add in the future. Basically to clarify my question is, how can I signify that BOTH of the buttons are selected and the "Breed" button is clicked? Thanks for any and all help guys!!!

local BUTTON = script.Parent
local TOOL = script.Parent
local NAME1 = "Bull"
local NAME2 = "Cow"
local DEEDS = game.Lighting.Animals
local DEED1 = DEEDS:findFirstChild(NAME1)
local DEED2 = DEEDS:findFirstChild(NAME2)
local AFRAME = script.Parent.Parent.Parent
local NEWBUTTON = AFRAME.newButton

--not sure if i need multiple functions, maybe one for recognizing the two buttons being selected
--and one for the "Breed" button being selected? 
function on_button1_down()
	
NEWBUTTON.MouseButton1Down:connect(function()
			local current = NEWBUTTON
			
		end)
end
---------------------------------

2 answers

If you want to have it so when both buttons are pressed it fires, it should look something like this.


created = false
name = false


function click ()

if name and created then

--Action would be here

	end
end
SCRIPT.MouseButton1Down:connect(click)

So created and name would be connect to a function, Say when the players types his name and presses "Enter". You would set created or name to true. If this didn't help you I apologize as I may have thought your question meant something different.

2 comments

0

so could I make the action be when the Breed Button is clicked? and are "name" and "created" the names of the two buttons in this example?

0

No, name and created would be the variables. You would say, "If the Part you want clicked is clicked, You would set the name variable to true. So when the brick is clicked, You would set the variable to true

So OpticalAce would this work as a base to work off of?

local BUTTON = script.Parent
local TOOL = script.Parent
local NAME1 = "Bull"
local NAME2 = "Cow"
local DEEDS = game.Lighting.Animals
local DEED1 = DEEDS:findFirstChild(NAME1)
local DEED2 = DEEDS:findFirstChild(NAME2)
local AFRAME = script.Parent.Parent.Parent
local NEWBUTTON = AFRAME.newButton
created = false
name = false


function click ()

if name and created then
	created = true
	name = true

function onMouseButton1Down()
	
print("complete")
    end
end
BUTTON.MouseButton1Down:connect(click)
BUTTON.MouseButton1Down:connect(on_button1_down)

This discussion is preserved as it was. New answers, comments, and votes are closed.