Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to check if multiple parts have the same value?

Asked by
cancle5 120
3 years ago

Basically, I have 5 parts and in each part there's a value. Who can i check if all the values are the same.

I didnt want to do a for i, v in pairs since i wanted to do it all at once. Yes all the parts are the same

1 answer

Log in to vote
1
Answered by
sydre 229 Moderation Voter
3 years ago
if part1.valueName.Value == part2.valueName.Value and part2.valueName.Value == part3.valueName.Value and part3.valueName.Value == part4.valueName.Value and part4.valueName.Value == part5.valueName.Value then
    -- Your code here
end

Not sure why you wouldn't want to use an in pairs loop though, considering that it would make the code easier to read as well as making it more adaptable:

local parts = {part1, part2, part3, part4, part5}
local previousValue = nil
local sameValue = true

for _, part in pairs(parts) do
    if previousValue and part.valueName.Value ~= previousValue then
        sameValue = False
        break
    end
    previousValue = part.valueName.Value
end
Ad

Answer this question