Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help With Making Things Transparent?

Asked by
Scootakip 299 Moderation Voter
8 years ago

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.

0
What exactly do you mean by "objects"? grasheeno 70 — 8y

2 answers

Log in to vote
0
Answered by
Vezious 310 Moderation Voter
8 years ago
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.

Ad
Log in to vote
0
Answered by 8 years ago

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..)

Answer this question