Damage script wont work for tool

I need help with this weapon I am making, for a fighting game. the animated weapons are supposed to hit people and damage them. Server script:
function onTouched(hit)
local human = hit.Parent:findFirstChild(“Humanoid”)
if (human ~= nil) then
human.Health = human.Health -40
end
end
script.Parent.Touched:connect(onTouched)

and the local script inside the tool performing the animation:
local Tool = script.Parent

Tool.Activated:Connect(function()
local Character = Tool.Parent
local Humanoid = Character.Humanoid

local AnimationTrack = Humanoid:LoadAnimation(script.Parent.Animation)
AnimationTrack:Play()

script.Parent.Animation.Parent = script

wait(9)
script.Animation.Parent = script.Parent

end)
there are no problems inside of the dev console.
script setup:
Screenshot 2020-10-29 120001

Do you get any errors in your output? Also could you format the code neater. Its hard to read the code when one part of the code is formatted and then randomly it is not formatted.

No, not a single error. I already said that in the post. I also tried formatting it, but for some reason I cant. I have no other explanation for that.

Try this:

human:TakeDamage(40)
1 Like

I just tried it, and it didn’t work. nothing in the dev console again.

local human = hit.Parent:findFirstChild(“Humanoid”)

Think you spelled FindFirstChild wrong. Uppercase the F

Okay I will try that. Thanks for pointing it out

That didn’t work either though, I also think the dev console would have pointed it out.

though I think I found the problem, the way I am getting this tool is by gui. the tool is inside the gui and I think thats why. I need to find a way to make the damage work yet give the tool to the player with the gui.

Try:

script.Parent.Touched:Connect(function(Hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local Human = hit.Parent:FindFirstChild("Humanoid")
        Human:TakeDamage(40)
   end
end)
1 Like

I don’t see anything wrong with the code. Is the hitbox welded to the handle? I see a weld within the hitbox is that connected to the handle?

I already tried a script like that. I think I just need to find out how to make it so the damage script works when I give it to the player from a starter gui. I tried by putting it in starter pack, and it seems to work. Tell me if you can help me with this since Its crucial to have the weapon given by gui.

Yes. Read the response to Valued source.

I have actually fixed this myself, thanks for the feedback everyone!