How to make A sword can only kill Zombies?

ive tried search most on youtube and find nothing but a not working sword
pls lemme know if y find an Sword that only can kill Zombies :3 thx

ive tried making the handle that damaging the Zombies only
but itsnt working

local part = script.Parent --
local Debounce = false --(Cooldown)

part.Touched:Connect(function(OtherPart)
	if not OtherPart:IsDescendantOf(workspace.misc_) then
		return 
	end
	if Debounce == false then
		Debounce = true         --Cooldown
		local Char = OtherPart:FindFirstAncestorOfClass("Model").Name = "Zombie"
		local Humanoid = Char.Humanoid
		Humanoid:TakeDamage(50) 
		task.wait()
		Debounce = false
	end		--Debounce
end)

Your Char line is not checking for if the parent is a zombie; this script will error out. Instead, you need with an if statement to check for the name:

local part = script.Parent --
local Debounce = false --(Cooldown)

part.Touched:Connect(function(OtherPart)
	if not OtherPart:IsDescendantOf(workspace.misc_) then
		return 
	end
	if Debounce == false then
		Debounce = true         --Cooldown
		local Char = OtherPart:FindFirstAncestorOfClass("Model")
		if not Char or not Char.Name == "Zombie" then
			return
		end
		local Humanoid = Char.Humanoid
		Humanoid:TakeDamage(50) 
		task.wait()
		Debounce = false
	end		--Debounce
end)
1 Like

image

What does it say when you hover over the red line?

1 Like

nothing :v its just kinda bother me bruh
btw how d y make it only Damaging when only Tool is activated

Just check if the tool is activated using Tool.Activated in the touched event before you carry out the damage (note that Tool is not defined you have to set that yourself):

if not Tool.Activated then
	return
end

wright as …

if not Char or Char.Name ~= "Zombie" then
    return
end
2 Likes

Haha yes forgot that the ~= operator exists.

Ya it saved ya here … may even want to split them two up to be sure (if even to test).
good luck!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.