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

Help With Making Things Transparent?

Hey, I need help with something

for i, MTwoK in pairs(game.Workspace.RoomTwo.Koolaid:GetChildren()) do
		MTwoK.Transparency = 1
		MTwoK.CanCollide = false
	end

I'm using that script to make an NPC transparent, the only problem is that since the group that makes up the NPC contains objects other than bricks (Objects that don't have Transparency and CanCollide variables) it won't take and just ends the script at an error. How can I fix this issue.

1 comment

0

What exactly do you mean by "objects"?

2 answers

✓ Accepted answer
for i, MTwoK in pairs(game.Workspace.RoomTwo.Koolaid:GetChildren()) do
if MTwoK:IsA("BasePart") then
        MTwoK.Transparency = 1
        MTwoK.CanCollide = false
    end
end

:IsA("BasePart") checks to see if MTwoK's classname is a BasePart. All Baseparts have Transparency and CanCollide, so it should not error.

For your for loop you currently have, I would suggest having an if statement checking if the objects are actual "BaseParts". Below I added your code with the added check, Try adding it in to your game and comment if you need anymore help! :)


for i, MTwoK in pairs(game.Workspace.RoomTwo.Koolaid:GetChildren()) do 
	if MTwoK:IsA("BasePart") then
        	MTwoK.Transparency = 1
        	MTwoK.CanCollide = false
	end
 end

With this fix, this allows the script to check if the part is actually a "BasePart" (A basepart is any part that is actually a block type ex: Wedge, Sphere, Cylinder, etc..)

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