alright for this script right here the explosion does print the parts it hit that are not locked but it also runs the if statement even when the basePart.Parent.Name does not equal Blue or Red it also destroys anything that is within a model and give a parent is nil value error and workspace is locked error
script:
workspace.ChildAdded:Connect(function(obj) if obj:IsA("Explosion") then obj.Hit:Connect(function(basePart, distance) print(basePart.Name) if basePart.Parent.Name == "BlueBarrel" or "RedBarrel" then basePart.Parent:Destroy() end end) end end)
What you do in your code is a very common mistake new developers do when using "if" statements.
The thing with Lua (could apply to other languages as well) is that you need to provide what it should check.
Basically in your if statement here:
if basePart.Parent.Name == "BlueBarrel" or "RedBarrel" then
you check if the basePart's parent name is "BlueBarrel" or if "RedBarrel" exists. Since "RedBarrel" is not falsy (AKA. false, nil etc.), but exists, this will return true and the if statement will return true.
You probably thought that it would check if the basePart's parent name was "BlueBarrel" or "RedBarrel".
There is not much you have to change though:
if basePart.Parent.Name == "BlueBarrel" or basePart.Parent.Name == "RedBarrel" then -- Continue end