How do I check if two bool values are true?

What do I mean? I want to make it so I invoke the Remote Function whenever two bool values are true, and I don’t know how to do that.
So here’s how my Rock, Paper, Scissors script will work:
LocalScript:
Whenever two bool values are true it’s going to invoke the server
Script:
Will add gametags to the players that are stored in ReplicatedStorage(I mean their name)
GUI Script(LocalScript):
Whenever it finds the players gametag it makes the UI enabled only for that player using playergui.

Edit: I want to check them both in functions and not if, else statements as they check once and doesn’t check if it has changed or not.

Can’t you check if their values changed and then check the values?

Example

local bool1 = script.Parent.Bool1
local bool2 = script.Parent.Bool2

bool1.Changed:Conenct(function(newVal)
	if newVal and bool2.Value then
		--Do stuff
	end
end)

bool2.Changed:Connect(function(newVal)
	if bool1.Value and newVal then
		--Do stuff
	end
end

I would recommend making a function for both the code in those 2 events so you don’t duplicate code

Oh, so you mean one of the functions will invoke the server as you check all the bool values in two functions? I’m going to try this out.

If you’re referring to adding a function to do the code for both of them, I mean something like this

local bool1 = script.Parent.Bool1
local bool2 = script.Parent.Bool2

local function doSomething()
   --Do stuff
end

bool1.Changed:Conenct(function(newVal)
	if newVal and bool2.Value then
		doSomething()
	end
end)

bool2.Changed:Connect(function(newVal)
	if bool1.Value and newVal then
		doSomething()
	end
end

As an example since you’d repeat code twice

1 Like

Okay, thanks for the response! I’ll be trying to implement this really soon!

For this, it would be better to use Changed and a separate function for checking. Example:

local bool1 = script.Parent.Bool1
local bool2 = script.Parent.Bool2

local remoteEvent = game:GetService(“ReplicatedStorage”).remoteEvent — Change this for wherever the event is located

function doSomething()
     remoteEvent:FireServer()
end

function checkIfTrue()
    if bool1.Value and bool2.Value then
        doSomething()
    end
end

bool1.Changed:Connect(checkIfTrue)
bool2.changed:Connect(checkIfTrue)

2 Likes

Wow, I am going to try this out! So this is basically going to call the function whenever the property changed.

1 Like

I mean they both do the same thing, check if a value is changed in a BaseValue. The only thing that you did that I didn’t was a function to reduce repetition for the condition checking. I just used Changed since I’m used to it

Yep, they do the same thing. It just cuts a few lines, but your solution is true too.

1 Like

Actually, your won’t work. Changed passes the property that was changed as a parameter; you think it will pass the new value. Also, .Changed fires when ANY property is changed. Whether that be name, parent, etc. Read more here: Instance | Roblox Creator Documentation

Mine is more efficient, also you misunderstand what parameters are passed through. For example, you think it will pass true or false, when it actually passes “Parent”, “Transparency”, “Value”, etc.

Is there anything else you need help on, or was that it? If that was it, then go ahead and mark a post as an answer so future people know it was solved. If you need help with remote events, comment here.

That’s for instances, .Changed for BaseValues works only if the Value is changed

Evidence

Also wait why is your code firing a remote event when @OP wanted to Invoke a Remote Function?

1 Like

What you did is a good idea, but its unnecessary if the dev knowns that any other property will not be changed

I already revised the script. Check again. Also, your wrong. How do I check if two bool values are true? - #12 by EmbatTheHybrid

Also it is not unnecessary. There is no performance differences. And the other values may change on accident. But non of this matters because of the link above.

Embat just shown a link to the page of how .Changed work, and now we gotta say that both make the same.

The way .Changed works with base values is just with the value. Therefore, for base values:

BaseValue.Changed:Connect() = BaseValue:GetPropertyChangedSignal(“Value”):Connect()

Also I have no idea what that last part meant.

That is correct for the most part. The only difference is that .Changed returns the new value of the BaseValue as a parameter but GetPropertyChangedSignal doesn’t. So both have their use cases depending on what is needed, but generally .Changed is better imo cause it’s simpler

1 Like

Oh i see, sorry i was a bit confused, anyways, i mostly consider a good practice to use :GetPropertyChangedSignal() in objects that arent values due to the sake of simplicity (.Changed) and debugging, due i prefer getting the error for accidentally calling the value, but now that i can think it, i can just print whatever has been changed too. Choice is left to the developer