Is there a way I can always have the person getting hit to knockback away from the player?
local parent = script.Parent
local Handle = parent:WaitForChild("Handle")
CanDmg = false
Can = true
damage = 24.5
cd = 0.44
TouchEnabled = false
parent.Activated:Connect(function()
local function slash()
if Can == true then
Can = false
TouchEnabled = true
CanDmg = true
Handle.Swing:Play()
wait(.36)
CanDmg = false
wait(cd)
Can = true
TouchEnabled = false
end
end
slash()
end)
function on(Touch)
if not TouchEnabled then return end
local Humanoid = Touch.Parent:FindFirstChild("Humanoid")
if Humanoid ~= nil and CanDmg == true then
local effects = script.Blood:clone()
effects.Parent = Humanoid.Torso
effects.Enabled = true
effects.EffectScript.Disabled = false
Humanoid:TakeDamage(damage)
CanDmg = false
Handle.Swing:Stop()
Handle.Hit:Play()
if Humanoid.Health <= 0 then
print("KILLED!")
end
local BV = Instance.new("BodyVelocity")
BV.MaxForce = Vector3.new(999999,999999,999999)
BV.Velocity = Humanoid.Torso.CFrame.LookVector * -14
BV.Parent = Humanoid.Torso
wait(0.1)
BV:Destroy()
end
end
Handle.Touched:Connect(on)
I modified your script and made it easier to read, kind of.
local tool = script.Parent
local Handle = tool:WaitForChild("Handle")
local CanDmg = false
local debounce = true
local damage = 24.5
local cd = 0.44
local TouchEnabled = false
local function slash()
if not debounce then
return
end
debounce = false
TouchEnabled = true
CanDmg = true
Handle.Swing:Play()
task.wait(0.36)
CanDmg = false
task.wait(cd)
debounce = true
TouchEnabled = false
end
local function onTouch(Touch)
if not TouchEnabled then return end
-- Here
local playerTorso = tool.Parent.Parent.Torso
-- is the update
local Humanoid = Touch.Parent:FindFirstChild("Humanoid")
if Humanoid == nil or not CanDmg then
return
end
local effects = script.Blood:clone()
effects.Parent = Humanoid.Torso
effects.Enabled = true
effects.EffectScript.Disabled = false
Humanoid:TakeDamage(damage)
CanDmg = false
Handle.Swing:Stop()
Handle.Hit:Play()
if Humanoid.Health <= 0 then
print("KILLED!")
end
local BV = Instance.new("BodyVelocity")
BV.MaxForce = Vector3.new(999999,999999,999999)
BV.Velocity = playerTorso.CFrame.LookVector * -14
BV.Parent = Humanoid.Torso
task.wait(0.1)
BV:Destroy()
end
tool.Activated:Connect(slash)
Handle.Touched:Connect(onTouch)
I just find the torso whenever the sword is trying to slash and damage.
Thanks it worked. I did have to change line 29 to “local playerTorso = tool.Parent.Torso” and line 51 to “BV.Velocity = playerTorso.CFrame.LookVector * 14”. thanks for the help!