How do i detect if part touched another part that has bool value

what i mean by bool value is this
Безымянный

i want to make attack that can certain destroy parts only if it has bool value

of course i know where to start like

attack.Touched:Connect(function()

end)

(attack is a part that should touch something)

what next should be

Use FindFirstChildWhichIsA() Instance | Documentation - Roblox Creator Hub

attack.Touched:Connect(function(obj)
 if obj.Parent:FindFirstChildWhichIsA("BoolValue") and obj.Parent:IsA("BasePart") then 
   local val = obj.Parent:FindFirstChildWhichIsA("BoolValue")
   if val.Name == "CanBeDestroyed" and val.Value == true then 
   -- Your code goes here.
   end
end)
1 Like

If it’s just a single part, that doesn’t have any parents, you could do

attack.Touched:Connect(function(obj)
 if obj:FindFirstChildWhichIsA("BoolValue") and obj:IsA("BasePart") then 
   local val = obj:FindFirstChildWhichIsA("BoolValue")
   if val.Name == "CanBeDestroyed" and val.Value == true then 
     -- Lets say you wanted to destroy the part, with making an explosion!
    local EXP = Instance.new("Explosion")
    EXP.Parent = obj
    EXP.BlastRadius = 30
    EXP.Position = obj.Position
    task.wait(3)
    obj:Destroy()
   end
end)
1 Like

part doesnt get destroyed for some reason

it used to get destroyed but now it doesnt

Are you sure that your part isnt in an another object?

doesnt work still

even if it doesnt i still appreciate your time thanks

Could be that you set the CanBeDestroyed to false. Either way I think its more efficient and easier to use Tags(Collection Service)

if im not wrong but there should be a pluggin that allows you to use tags much more easier