How do i change the transparency in this for i and v code

Hello

I want to change the transparency of house 1 to 0 transparency in a “for i and v in pairs do code”

But when i want to do v.game.transparency it doesn’t seem to want to change them (dosent even come up for quick code)
I know i could do
Local house1 = {game.workspace.house.part}
But i just want to do get children then set the transparency
(Note when i do print(v) it comes up with all the parts) so it knows the children are all the parts.
(Note there are about 10 parts in the house folder)

What i have so far

Thank you

Can’t you just do v.Transparency to get the transparency property to then change? If no all children are parts, you’ll need to use an if statement that skips that child if it’s not a part

I’m pretty sure your problem is “game.” You can’t set the transparency of the world and it seems like you are looking for something named game inside of the parts you are looping through. You can use FindFirstChild() if you are trying to find an instance named game, which probably should have the name changed so it isn’t confused with the world. I would also check to make sure you are changing the transparency with :IsA() to make sure you are changing the transparency of BaseParts because you don’t want to run into an error.

v should be the instance that you are looping through and i should be the index.

Example:

for i, v in pairs(house1) do
    if v:IsA("BasePart") then
        v.Transparency = 0
    end
end
local house = game.workspace:WaitForChild("house")

for i, o in pairs(house:GetChildren()) do
	if o:IsA("BasePart") or o:IsA("Decal") then
		o.Transparency = 1
	end
end

It wont let me do v.transparency (dosent even come up as a quick code) and yes all the parts in the house are parts

Because Roblox’s quick code thing doesn’t know what v is interms of instance, You can do v.Transparency if you yourself know that they’re all parts, if the instance doesn’t have a Transparency Property, it’ll just error, simple as that

this is what i have but dosent work but thank you for trying

1 Like

I got rid if that second end so thats not the problem it does the code without error but dosent set the transparency to 0

Could you show me the error message more clearly? Like using the inbuilt snipping tool for windows. Using your phone is hard as I can’t see the error message due to the light.

Show me the explorer menu containing your house and the instances.
Also, let’s clean this up. You could just do “workspace” as it’s a predefined variable by Roblox. Second use WaitForChild(), which waits for the model to load before continuing the thread.

Third, check if your parts exist and are BaseParts. I’d do something like this.

local house = workspace:WaitForChild(“House”)

for _, part in pairs(house:GetChildren()) do
	if (part and part:IsA("BasePart")) then
		part.Transparency = 0
	end
end

try this this will work

local house = game.workspace:WaitForChild("house")

for i, o in pairs(house:GetChildren()) do
	if o:IsA("BasePart") or o:IsA("Decal") then
		o.Transparency = 1
	end
end

Doesn’t know what the or is and dosent know what then is

You didn’t add the “if” word. 30char

2 Likes

you forget to put the if

if o:IsA("BasePart") or o:IsA("Decal") then
	o.Transparency = 1
end
1 Like

Thank you so much got it (thank you everyone) im going to study how this code works and remember why it works.

Would you know what oIsA mean or is this on the roblox dev form somewhere?

In a nutshell, “IsA()” checks if an Instance is a specific kind of object.

You can learn more about it here:

1 Like

And the reason it was “o” is because thats what he used in the loop instead of v, to make it more clear here:

local house = game.workspace:WaitForChild("house")

for i, part in pairs(house:GetChildren()) do
	if part:IsA("BasePart") or part:IsA("Decal") then
		part.Transparency = 1
	end
end
2 Likes