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

Can I make a script that will destroy a part if it hits another?

I am currently making a drone and want to script it so it will be removed if it collides with another part.

The one thing I have tried so far is

script.Parent.Part.Touched

However I am aware that this only functions if a player hits it. Is there any alternative away that will function if the Brick collides with another brick?

Thanks.

1 answer

The event .Touched activates when a part touches a part, and of course all players have a character full of parts. However, they are linked from player to character and vice versa. Here are some methods:

An if statement detecting humanoids:

 if hit.Parent:FindFirstChildWhichIsA('Humanoid')==nil then
  print('hit detects no humanoid')
 end 
end)```

An if statement detecting player's character:
```targetPart.Touched:Connect(function(hit)
 if game:GetService('Players'):GetPlayerFromCharacter(hit.Parent)==nil then
  print('hit is not a part of a character')
 end
end)```

3 comments

0

Note i am a nub with putting in a code block

0

ew single quotes

0

Bruh [[ ]] superior but i prefer apostrophes

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