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

How to change transparency of everything inside?

How can I modify this script in order for everything inside "Pieces" to change Transparency, when the Transparency inside "Bags" are all zero. There are six bags in total inside the "Bags" model, they don't change transparency altogether as it requires the player to get in contact with the bags.

local bags = script.Parent.Bags:GetChildren()
local pieces = script.Parent.Pieces:GetChildren()

for i,bags in pairs(bags) do
	if bags.Transparency == 0 then
		print("all bags are visible...")
		for i,pieces in pairs(pieces) do
			pieces.Transparency = 0
			print("puzzle pieces are visible...")
		end
	end
end

1 comment

0

My issue is that, the pieces don't change transparency at all even though the transparency inside "Bags" are all 0.

1 answer

well, first off, and I’m not sure if this has an effect on the script or not, there’s no reason to use the same variable in the iterator and the loop variable. notice how you’re writing bags in pairs(bags), why not bag in pairs(bags)? same problem with the second loop. you are overwriting the same variable which could have unintended side effects, and be breaking your script (not 100% certain right now if that’s the issue however).

next thing, I take it you’re checking every bag for transparency at once. well on one line you wrote “all bags are visible” after checking only the first bag. there’s no good in that, not to mention it will run six times! you have to check all the bags and then make a decision.

function checkTransparency(instances)
    for _, instance in pairs(instances) do
        if instance.Transparency ~= 0 .then
            return false
        end
    end
    return true
end

if checkTransparency(bags) then
    for _, piece in pairs(pieces) do
        piece.Transparency = 0
    end
end

the function checkTransparency checks every bag and returns false if it finds a bag that is transparent. it only returns true if every bag passed the test. only then, can you set the transparency of the pieces.

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