So, I want to specify who the axe can hit. I am using transparent dummy’s placed inside a tree model to detect hits and to display damage. Right now the axe damages all humanoids. Is it possible to specify who the axe can damage using a name based system? is there a better solution to all of this? In the future, I want to add rocks and different types of trees, but an axe will only be able to damage trees not rocks. As you make new and better axes you will be able to hit new trees.
here is the code for my axe:
local tool = script.Parent
local canDamage = false
local function onTouch(otherPart)
local humanoid = otherPart.Parent:FindFirstChild("Humanoid")
if not humanoid then
return
end
if humanoid.Parent ~= tool.Parent and canDamage then
humanoid:TakeDamage(5)
print("Slashed")
else
return
end
canDamage = false
end
local function slash()
local str = Instance.new("StringValue")
str.Name = "toolanim"
str.Value = "Slash"
str.Parent = tool
canDamage = true
end
tool.Activated:Connect(slash)
tool.Handle.Touched:Connect(onTouch)