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

How can I check to see a if part hits any descendant of a model?

Asked by 6 years ago
Edited 6 years ago

So I need a part to destroy when it touches any part in the model "Scenery" but I don't know what I'm doing. Here's all I got:

local scenery = game.Workspace.Scenery:GetDescendants()

for index, descendant in pairs(scenery) do
    script.Parent.Touched:connect(function(descendant)
        script.Parent:Destroy()
    end)
end

this script goes inside the part that is supposed to get destroyed when it touches scenery

2 answers

Log in to vote
0
Answered by 6 years ago

This is actually fairly simple, just use one Touched event but in that function, check to see if the part touched is a descendant of the model.

local model = model -- Just an example

script.Parent.Touched:connect(function(part)
    if part.Parent == model then
        -- Continue
    end
end)
0
This won't work if the Part is a descendant of model. For example, if the Part were in a Folder in the Scenery model, this Touched event wouldn't fire. Zenith_Lord 93 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

I think you should make a function that destroys the part when it touches any of scenery's children. I would also put the script into serverscript storage and just name the part that is supposed to be destroyed... so maybe something like this (assuming all of scenery's children are parts and not models)

local scenery = game.Workspace.Scenery:GetChildren()

function destroyPart()
    game.Workspace.*PartName*:Destroy
end

scenery.Touched:connect(destroyPart)

I hope this helps now that I look at it I think it kind of looks like yours except without descendants. Also, this won't work if anything besides the part touches scenery since it will destroy the part.

Answer this question