How to make buttons that cannot be activated at the same time

Hello!

The title may be a bit confusing. But basically what I want to do is make sure two buttons aren’t activated at the same time, so if you press on the Private button and the the Public Button, it deactivates the Private Button.

I have made two bool values in my screengui:
image_2024-12-29_102008877
If the Private Button gets pressed then, PrivateValue = true, same with the Public Button and value.

I don’t want both of the values activated at the same time, so only one can be activated.

Here are the buttons:
image_2024-12-29_102245966

Also I would like for you to add to the existing scripts. The scripts are inside the image buttons and they change the “Rectangle 5” background colour when clicked.

Private Script:

local BTN = script.Parent
local Rectangle = script.Parent.Parent["Rectangle 5"]
local Clicked = false

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

local PublicVaule = script.Parent.Parent.Parent.Parent.Parent.PrivateValue
local PrivateVaule = script.Parent.Parent.Parent.Parent.Parent.PublicValue

PublicVaule.Value = false
PrivateVaule.Value = false

BTN.MouseButton1Click:Connect(function()
	if Clicked == false then
		
		Rectangle.BackgroundColor3 = Color3.fromRGB(177, 0, 0)
		Clicked = true
		PrivateVaule.Value = true
		
		
	else
		
		Rectangle.BackgroundColor3 = Color3.fromRGB(35, 0, 0)
		Clicked = false
		PrivateVaule.Value = false
		
		
	end
end)

Public Script:

local BTN = script.Parent
local Rectangle = script.Parent.Parent["Rectangle 5"]
local Clicked = false

local ReplicatedStrage = game:GetService("ReplicatedStorage")

local PublicVaue = script.Parent.Parent.Parent.Parent.Parent.PrivateValue
local PrivateVaue = script.Parent.Parent.Parent.Parent.Parent.PublicValue

PublicVaue.Value = false
PrivateVaue.Value = false

BTN.MouseButton1Click:Connect(function()
	if Clicked == false then
		
		Rectangle.BackgroundColor3 = Color3.fromRGB(12, 177, 0)
		Clicked = true
		PublicVaue.Value = true
		
		
		
	else
		
		Rectangle.BackgroundColor3 = Color3.fromRGB(19, 35, 0)
		Clicked = false
		PublicVaue.Value = false
		
		

	end
end)

Also here is the picture of the two buttons when both deactivated:
image_2024-12-29_102752417

Any Help?

1 Like

Maybe try disabling the public button when private is pressed and vice versa? Have you tried this one yet?

How would I do that? Would I need to make an if statement?

In the mouseButton just activate the button player clicked on, and disable the other one

I cant really access my pc right now so in theory this could work

Something like this?

if PrivateVaue.Value == true then
			PublicVaue.Value = false
			Rectangle.BackgroundColor3 = Color3.fromRGB(19, 35, 0)
			
		end
button.MouseButton1Down:connect(function()
    ---enable your button


    ---disable other one



end)

Try this one out

Just wanted to say that you can simplify things by using 1 integer/string value (depends on which you prefer) instead of 2 bool values to check if a button has already been activated (this would be very useful if you’re planning to add different types of Privacy buttons for your game, like Friends etc.)

I can try giving you an idea of how you can play this out (assuming you’re replacing PrivateValue and PublicValue with a IntValue:

  1. Player clicks on Public button.
  2. PublicScript colors itself as activated and sets the IntValue to indicate that is has been selected
  3. Player clicks on Private button
  4. PRIVATEscript colors itself as activated and sets the IntValue to indicate that is has been selected
  5. PublicScript detects that the IntValue has changed, verifies that the current value indicates that the Public button isn’t selected, and colors itself as deactivated.

Instead of disabling buttons, you can also try just overriding what the Player has selected for the convenience of the Player.

1 Like

Also, sorry, i think it says “:Connect” instead of :connect"

This one is good if you want to use bool value in any other scripts so this may be actually better

Will try your solutions after 5 minutes!

I don’t know why, but I have two double-click on the other button to activate it

script: PublicScript

if Clicked == false then
		
		Rectangle.BackgroundColor3 = Color3.fromRGB(12, 177, 0)
		Clicked = true
		PublicVaue.Value = true
		RectanglePrivate.BackgroundColor3 = Color3.fromRGB(35,0,0)
		PrivateVaue.Value = false
		
		
		
	else

If you’re using different scripts in your case you can place them under 1 parent (not necessary) and just disable/destroy one of them when button is pressed, this will disconnect your “MouseButton1Click” event and this will prevent activation.

But I’d recommend you to merge scripts into one and handle all that in it. :grinning:

That’s because of this variable you’ve placed in both scripts:

Since this specific variable isn’t updated when you try and force the Private button to be deactivated, you’ll need to click on the Private button twice to actually enable it.


For the sake of being organized and simplifying code, I’d still recommend you to use 1 IntValue/StringValue instead of 2 BoolValues:
image

And instead of creating the Clicked variable for both scripts, just use this singular IntValue/StringValue you created to determine which button is activated.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.