generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: ClassName - Property

Previous Thread :: Next Thread 
Serene518 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. Serene518
Joined: 05 Jul 2014
Total Posts: 291
10 Sep 2014 12:13 PM
Thank you guys.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image