Katana damaging players not working!

I’m making a katana, so far I have made the local side or animations script. Everything else works until I get to the damaging script or the server script.

The issue is, during the local script it detects when the katana is activated then it plays the animations while setting a bool value to true. Then in the server script, when the blade is touched, it checks to see if the bool value is true and if so then it is suppose to damage the player that was hit by the blade. But its not doing that and I am stuck here.

Server script:

local sword = script.Parent
local blade = sword.Blade
local handle = sword.Handle

local hitSound = handle.Hit

local canDamage = sword.CanDamage
local damage = 25

blade.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if canDamage.Value == true then
			canDamage.Value = false
			hitSound:Play()
			hit.Parent.Humanoid:TakeDamage(damage)
		end
	end
end)
1 Like

Instead of using blade.Touched, try using raycasting, which is far more effiicient

Can you suggest how would I do this?

Try this:

local sword = script.Parent
local blade = sword.Blade
local handle = sword.Handle
local deBounce = false

local hitSound = handle.Hit

local damage = 25

blade.Touched:Connect(function(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
	if humanoid then
		if deBounce == false then
			deBounce = false
			hitSound:Play()
			humanoid:TakeDamage(damage)
            task.wait(1)
            deBounce = false
		end
	end
end)

You are changing the bool value, but never setting it back, therefore it’ll only work once. Feel free to change the ‘task.wait(1)’ it is just a pro-caution for your animations.

Also, @Stickmanfanrdc, I would not recommend RayCasting in this situation, for RayCasting would be better for guns, not swords.

It’s not working, there isn’t any errors coming from the output. I think it might have something to do with the debounce.

I don’t think you understand how raycasting works… You raycast from an attachment at the end and start of the blade? Must better on performance aswell

Oops, my bad. I was not aware that your if statement for the deBounce was checking for a true value instead of a false bool, try it now it should work.

I’m not sure, seems more simple to simply wait for the touch event.

1 Like

No, it may be a bit simpilier but raycasting would be most efficent and overall better quality for swords, and guns.

Many famous games use raycasting just because of this

Is there anything you can refer me to that will show me how to add raycasting to the sword?

A very simple module made exactly for this:

Raycasting is far more accurate and can provide better results. Though this can work as well. To fix this check YT, there are about 100 tutorials, I have do have code for it but not on hand.