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

How do I tell if one parts parent is the same as the other?

So for example, I have this script:

local model = workspace.Plots["1"].Building

model.ChildAdded:Connect(function()
	for name, child in pairs(model:GetChildren()) do
		child:WaitForChild("Hitbox").Touched:Connect(function(hit)
			if hit.Parent ~= child then
				child:Destroy()
			end
		end)
	end
end)

Basically, it creates a new part and if it is touching that other part it will check if it has the same parent. If it doesn't it will destroy that model.

1 answer

local model = workspace.Plots["1"].Building

model.ChildAdded:Connect(function()
    for name, child in pairs(model:GetChildren()) do
        child:WaitForChild("Hitbox").Touched:Connect(function(hit)
            if hit.Parent.Name == child.Parent.Name then
                child:Destroy()
            end
        end)
    end
end)

boop

2 comments

0

nonononono, dont check the name, check the object instead as he did

0

lemme try that

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