Ad
Log in to vote
0

How to check if multiple parts have the same value?

Asked by
cancle5 105
8 days 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 214 Moderation Voter
8 days 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