How to check if multiple part are Transparency = 1 with an if statement

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear

To make an if statement which checks if multiple unique parts are Transparency=1/transparent

  1. What is the issue? Include screenshots / videos if possible!

Not being able to check

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

Tried finding something about this around the developer hub and I did try the tables but it don’t seems to work well.

Hi, just loop through all the parts. If one of them is not equal to transparency 1, then break the loop and return “success” as false.

1 Like

I don’t believe you can in lua, if overhead isn’t a problem then the best other option is iterating through all your parts

local success = true
for _, TargetPart in model:GetChildren() do
	if TargetPart.Transparency == 1 then continue; end -- just avoiding another scope here, you can change this if you don't like it
	success = false
	break
end

if success then
	-- blah blah
end
1 Like

So I tried to use that and adapt it to my script and I added a new model to test it out, made the part transparent, and it still don’t end up with success, so Idk if I did anything wrong.
Here is my script if you want to check it out :

local ReplicatedStorage =  game.ReplicatedStorage.KeysRemote.KEYCHECKER
local ProximityPrompter = script.Parent

ProximityPrompter.Triggered:Connect(function(player)
	local success = true
	for _, TargetPart in game.Workspace.test:GetChildren() do
		if TargetPart.Transparency ~= 1 then continue; 
			
		end
		success = false
		 print("failed")
		break
	end
	wait(2)
	if success then
		print("Succes")
	else
		print("not success")
	end
end)

oh sorry I misread your post, the code I provided was checking if all the parts aren’t transparent, you can replace the ‘not equal to’ operator ~= with an ‘equal to’ operator == to fix it

Thank you ! It works perfectly!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.