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)
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.
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.
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.