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

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

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

✓ Accepted answer

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)

1 comment

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.

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.

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