Serene518
|
  |
| Joined: 05 Jul 2014 |
| Total Posts: 291 |
|
|
| 10 Sep 2014 10:23 AM |
I want to make an NPC that disables CanCollide for all the parts inside the model when the NPC is killed.
How do I make a script to find all of the objects with the same ClassName "Part" inside of the model, and then disable CanCollide for all of the parts? |
|
|
| Report Abuse |
|
|
vlekje518
|
  |
| Joined: 10 Apr 2011 |
| Total Posts: 191 |
|
|
| 10 Sep 2014 10:43 AM |
humanoid = script.Parent:WaitForChild("Humanoid") humanoid.Died:connect(function() for _, v in pairs(script.Parent:GetChildren()) do if v.ClassName == "Part" then v.CanCollide = false end end end) |
|
|
| Report Abuse |
|
|
Serene518
|
  |
| Joined: 05 Jul 2014 |
| Total Posts: 291 |
|
|
| 10 Sep 2014 11:47 AM |
I added what you gave me, but there's an error. I'm using a model that is meant to clone after dying. I'm getting the error about "Parent" on line 14 returning nil. Also the parts' CanCollide isn't being disabled. Here's my script. If you or anyone else can fix it or write a script that will give me the desired effect, I'd greatly appreciate it.
z = script.Parent:clone() h = script.Parent:WaitForChild("Humanoid")
while wait(1) do if script.Parent.Humanoid.Health <= 1 then wait(2) zombie = z:clone() zombie.Parent = script.Parent.Parent zombie:makeJoints() for _, v in pairs(script.Parent:GetChildren()) do if v.ClassName == "Part" then v.CanCollide = false wait(1) script.Parent:remove() end end end end |
|
|
| Report Abuse |
|
|
Nyxis
|
  |
| Joined: 15 Nov 2012 |
| Total Posts: 3374 |
|
|
| 10 Sep 2014 11:51 AM |
just a tip: use ":IsA()" to check something's ClassName, it's easier.
ex: if x:IsA("BasePart") then --stuff end
I mean, you don't have to.. what ever you prefer. |
|
|
| Report Abuse |
|
|
Bobobob12
|
  |
| Joined: 23 Jan 2008 |
| Total Posts: 5350 |
|
|
| 10 Sep 2014 11:53 AM |
| IsA seems to be better since it actually checks for parts whose class is derived ie IsA("BasePart") returns seats, vehicleseats, parts, and so forth |
|
|
| Report Abuse |
|
|
Serene518
|
  |
| Joined: 05 Jul 2014 |
| Total Posts: 291 |
|
| |
|