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:
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:
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:
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:
Player clicks on Public button.
PublicScript colors itself as activated and sets the IntValue to indicate that is has been selected
Player clicks on Private button
PRIVATEscript colors itself as activated and sets the IntValue to indicate that is has been selected
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.
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.
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:
And instead of creating the Clicked variable for both scripts, just use this singular IntValue/StringValue you created to determine which button is activated.