Dont worry all the other errors that appear in the output, they are intentional.
And I did check if one of the errors are from the script i’m using, but no, none of them are related.
As you can see the print("All Values true") fire’s when only one of the value changes to true, but the idea is that when all of them are true at the same time.
Instead of determining if a value is true, establish if a value is false and storing it as a bool, in a separate variable; doing so enables any presence of a false condition to acknowledge the table is false rather than constantly confirming if a table is true. If that makes sense?
Here is an example, I hope this helps:
local t = {true, false, true, true}
local isTrue = true
for i, v in ipairs(t) do
if not v then
isTrue = false
end
end;
print(isTrue)
--
local t = {true, true, true, true}
local isTrue = true
for i, v in ipairs(t) do
if not v then
isTrue = false
end
end;
print(isTrue)
But now how can I make it re check when any of the values change. For some reason using :GetPropertyChangedSignal() and .Changed don’t fire when the values are being changed.
Script currently using:
for A,B in pairs(script.Values:GetChildren()) do
B:GetPropertyChangedSignal("Value"):Connect(function() --For some reason, it doesn't work, when it works just fine for other scripts
local Values = {}
local Acquired = true --Placed variables here to reset them when function called
table.insert(Values,A,B.Value) --I dont have to manually insert the values myself
for A,B in ipairs(Values) do
if not B then
Acquiered = false --Works awsomely
end
end
end)
end
Weirdly, yesterday the script was able to register the values changing from a For loop using B.Changed. Now it doesn’t work. How should I have the function run every time a value is changed?
EDIT: I have also tried
function CheckValue()
--function
end
for A,B in pairs(script.Values:GetChildren()) do
B.Changed:Connect(CheckValue)
end
If you’re changing the values on the client then those changes will not replicate to the server and thus any server scripts listening for their changes with “:GetPropertyChangedSignal()” or “.Changed” will not detect any changes.
The issue with this implementation is that anything which isn’t “nil” or which isn’t “false” is considered truthy, i.e; 1, 2, 3, “a”, “b”, “c” etc.
Here’s a function which determines if the values of an array or a dictionary are truly true, it will return true if so, false if not and nil if the argument passed to it is not a table value.
local function isAllTrue(tables)
if type(tables) == "table" then
for key, value in pairs(tables) do
if type(value) == "boolean" then
if not value then
return false
end
else
return false
end
end
return true
end
end
local isTableTrue = isAllTrue{["1"] = true, ["2"] = true, ["3"] = true}
print(isTableTrue) --true
I didn’t infer that in that scenario they wouldn’t work. I was referring to changing the values on the client (as that wouldn’t replicate to the server).