Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to check if multiple parts have the same value?

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

✓ Accepted answer
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

This discussion is preserved as it was. New answers, comments, and votes are closed.