I made a damaging part for a simple sword I made and it doesn't seem to work

local Damage = script.Parent.Parent.Parent.Damage

function onTouched(hit)
	local human = hit.Parent:findFirstChild("Humanoid")
	if (human ~= nil) then
		human.Health = human.Health - Damage
	end
end
script.Parent.Touched:connect(onTouched)

The main script just plays animations and turns on CanTouch for the damage part.
Probably some really easy fix but i aint too good.

just add Damage.Value if damage is an intvalue

It still doesn’t appear to do anything.

check if cantouch property is set to true before the sword is touched

Yeah it is set to true, or at least it should be.

you have to check, I have an idea, what if you add a delay before the function runs, example:

game:GetService(“RunService”).HeartBeat:Wait()
script.Parent.Touched:connect(onTouched)

1 Like

Add .Value here

human.Health = human.Health - Damage.Value

It hasn’t changed anything, maybe there is an error with my main script Afterall.

send main script so I can check it

local Tool = script.Parent
wait(1)
local Animation = Tool.Slash1
local Player = game.Players
local LocalPlayer = Player.LocalPlayer
local Char = LocalPlayer.Character
local Humanoid = Char:WaitForChild("Humanoid")
local AnimationTrack = Humanoid:LoadAnimation(Animation) --Animations, Important
local DmgPart = script.Parent.Handle.DmgPart


AnimationTrack.Priority = Enum.AnimationPriority.Action

Tool.Activated:Connect(function()
		AnimationTrack:Play()
		DmgPart.CanTouch = true
		print("Playing")
		wait(1)
		DmgPart.CanTouch = false
end)

First of all, set the damage part’s parent to the tool and why don’t you just disable the damagescript instead of changing can touch property

also set the handle’s cantouch property to false

Thought that mightve fixed it but sadly it did not.

are you getting any error in the output?
Also is the mainscript a Local or normal Script?

No errors whatsoever and the mainscript is a Local script, the damage one is a regular script.

local Damage = script.Parent.Parent.Parent.Damage

function onTouched(hit)
    if hit:IsA("BasePart") then
	    local human = hit.Parent:findFirstChild("Humanoid")
	    if (human ~= nil) then
		    human.Health = human.Health - Damage
	    end
    end
end
script.Parent.Touched:connect(onTouched)

turn the kill script into a localscript

That would mean that he would only die for the client, but the guy who got hit won’t die.

actually no, when you change health property from a humanoid it dies for the server

I made a gun script once, and added the kill script as a localscript and it was really confusing. Plus, that would defeat the whole purpose of using a localscript for the kill script instead.