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

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

Asked by 5 years ago

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

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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: targetPart.Touched:Connect(function(hit) 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)

0
Note i am a nub with putting in a code block SoftlockedUnderZero 668 — 5y
0
ew single quotes DeceptiveCaster 3761 — 5y
0
Bruh [[ ]] superior but i prefer apostrophes SoftlockedUnderZero 668 — 5y
Ad

Answer this question