Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My sword script isn't doing damage and returns no error, what am I doing wrong?

Asked by 3 years ago

I've placed in multiple NPC's and tried to attack all of them, I debugged the script with print statements that showed me all the code was being run through but there was no damage done.

local tool = script.Parent

local function onTouch(partOther)
    local humanOther = partOther.Parent:FindFirstChild("Humanoid")
    if not humanOther then return end
    if humanOther.Parent == tool then return end
    humanOther:TakeDamage(10)
end

local function slash()
    local str = Instance.new("StringValue")
    str.Name = "toolanim"
    str.Value = "Slash"
    str.Parent = tool
end

tool.Activated:Connect(slash)
tool.Handle.Touched:Connect(onTouch)

Answer this question