You're going in the right direction, just a couple of things wrong with your if-statement.
if part.Parent.Name ~= "Skelters" or part.Parent.Name ~= "Captain Stellus" or part.Parent.Name ~= "Lt. Brains" and h == nil then
What you've written, and what you're going for are two different things. First off, you want to make sure that you don't die if the character has ANY of those names, and so you shouldn't be using "or" between those, rather:
if part.Parent.Name ~= "Skelters" and part.Parent.Name ~= "Captain Stellus" and part.Parent.Name ~= "Lt. Brains"
That's what you're looking for.
As far as your "h==nil" is concerned, you have it backwards. You want to make sure that the humanoid IS present. Also, I would put that in an if-statement prior to looking for the names, so as to save your computer some time checking through the names.
if h ~= nil then
if part.Parent.Name ~= "Skelters" and part.Parent.Name ~= "Captain Stellus" and part.Parent.Name ~= "Lt. Brains"
As an aside, I would use a different method so as to keep your code clean in the future: Use an array alongside a loop to check for names, rather than just one large if-statement:
local Bosses = {"Skelters", "Captain Stellus", "Lt. Brain"};
script.Parent.Touched:connect(function(part)
local h = part.Parent:findFirstChild("Humanoid");
if(h) then
local ItsABoss = false;
for i, v in pairs(Bosses) do
if(part.Parent.Name == v) then
ItsABoss = true;
break;
end
end
if(ItsABoss == false) then
h.Health = 0;
end
end
This way, you can add bosses to the table "Bosses" easy-peasy.
Hope that helps!
2 comments
Why do you have "and h == nil" ??
Because I need to make sure that it is a human