I have a rocket that when something touches the tip, it explodes. However, when I drop it, it explodes because it collided with itself. How do I tell it not to explode if they collide with a part of a rocket? here's the script:
01 | local model = script.Parent.Parent |
02 | model.PrimaryPart = model.Base |
03 | model.Base.Fire.Enabled = true |
04 |
05 | local explosionPart = script.Parent |
06 | while true do |
07 | wait() |
08 | script.Parent.Parent:SetPrimaryPartCFrame(script.Parent.Parent.PrimaryPart.CFrame * CFrame.fromEulerAnglesXYZ( 0 ,. 1 , 0 )) |
09 | script.Parent.Touched:connect( function (hit) |
10 | if hit:IsDescendantOf(script.Parent.Parent) = = false then |
11 | local explosion = Instance.new( "Explosion" , game.Workspace) |
12 | explosion.Position = explosionPart.Position |
13 | explosionPart.Parent:Destroy() |
14 |
15 |
16 | end |
17 | end ) |
18 | end |
So there is something called "CollisionGroups" and they can disable collision between another collison group or itself. It kinda goes like this:
1 | local PhysicsService = game:GetService( "PhysicsService" ) --This gets the service |
2 |
3 | PhysicsService:CreateCollisonGroup( "[name]" ) --Creates a collisiongroup |
4 |
5 | PhysicsService:CollisonGroupSetCollidable( "[group]" , "[group]" , [ true / false ] ) --Defines collison properties between 2 groups |
6 |
7 | PhysicsService:SetPartCollisonGroup(part, group) --adds a part to the collision group |
All you would need to do is make sure the rocket parts are in a collisiongroup and add the rocket to that group when it spawns.
Hope this helped! You can also find a post about this on the devforums, but I forgot the link.