I have a question, does Value.Changed actually detect if anything changed if the BoolValue was set to this:
True → True
or
False → False
I have a question, does Value.Changed actually detect if anything changed if the BoolValue was set to this:
True → True
or
False → False
The value didn’t actually change, just an unnecessary line of code was executed in futility.
In short, no.
Any other way I can detect this?
No, there is no way to detect this. The only real way would be to use RemoteEvents or other script connections telling your script that something was executed to change the value.
Check the value before you change it?
local function onAssigned(valueInstance, newValue)
--Do code.
end
if bool.Value then
bool.Value = true --Value set to true even though it's already true.
onAssigned(bool, bool.Value)
end
Something like this should do the trick.
Y̶e̶s̶.̶ ̶I̶t̶ ̶w̶i̶l̶l̶ ̶d̶e̶t̶e̶c̶t̶ ̶a̶n̶y̶t̶h̶i̶n̶g̶ ̶i̶t̶ ̶s̶e̶t̶s̶ ̶t̶o̶.̶ ̶E̶v̶e̶n̶ ̶i̶f̶ ̶i̶t̶’̶s̶ ̶t̶h̶e̶ ̶s̶a̶m̶e̶ ̶v̶a̶l̶u̶e̶.̶
Edit: Apologies, this statement is incorrect.
.Changed only fires when ANY property. If you set the value to what it was previously, then it doesn’t actually change, so the event doesn’t fire. You could do something like Value.Value = not Value.Value
which will change the value to the opposite if you’re using this to create an event
Not the case, unfortunately.
local bool = Instance.new("BoolValue")
bool.Value = true
bool.Changed:Connect(function()
print("Hello world!")
end)
bool.Value = true
task.wait(5)
bool.Value = false
"Hello world!’ only prints after 5 seconds have elapsed.