I have a script for a sword and I want when the sword hits the player character, it will do more damage if it hits the back.
I have tried to use Vector3:Dot() but it did not work I may of did it incorrectly
local Tool = script.Parent
local Handle = Tool.Handle
local Anims = Tool.Anims
local plrowner = script:FindFirstAncestorWhichIsA("Player") --player holding the part
local RaycastHitbox = require(game.ServerScriptService.RaycastHitboxV4)
local Hitbox = RaycastHitbox.new(Tool.Hitbox)
local de = false
local canHit = false
local combo = 1
config = {
Damage = 30,
AttackTime = 0.05,
Cooldown = .9
}
Hitbox.OnHit:Connect(function(hit, humanoid)
if canHit == false then return end
canHit = false
if humanoid.Parent ~= script.Parent.Parent and humanoid.Parent.Parrying.Value == false then
humanoid:TakeDamage(config.Damage)
task.wait(.35)
elseif humanoid.Parent.Parrying.Value == true then
print("ouchies")
plrowner.Character.Vulnerable.Value = true
plrowner.Character.HumanoidRootPart.Anchored = true
plrowner.Character.Star.Star.Transparency = 0
wait(2)
plrowner.Character.Vulnerable.Value = false
plrowner.Character.HumanoidRootPart.Anchored = false
plrowner.Character.Star.Star.Transparency = 1
end
canHit = true
end)
script.Parent.Hit1.OnServerEvent:Connect(function(Player)
if de == false then
de = true
local Humanoid = Player.Character.Humanoid
local AnimationsList = Anims:GetChildren()
local load = Humanoid:LoadAnimation(Anims.Slice1)
load:Play()
Player.Character.Attacking.Value = true
Tool.Hitbox["sword slash 1"]:Play()
Hitbox:HitStart()
Tool.blade.Trail.Enabled = true
wait(config.AttackTime)
canHit = true
Humanoid.WalkSpeed = 1
wait(config.Cooldown)
Player.Character.Attacking.Value = false
Tool.blade.Trail.Enabled = false
Humanoid.WalkSpeed = 12
Hitbox:HitStop()
canHit = false
de = false
end
end)
script.Parent.Hit2.OnServerEvent:Connect(function(Player)
if de == false then
de = true
local Humanoid = Player.Character.Humanoid
local AnimationsList = Anims:GetChildren()
local load = Humanoid:LoadAnimation(Anims.Slice2)
wait(config.AttackTime)
load:Play()
Player.Character.Attacking.Value = true
Tool.blade.Trail.Enabled = true
Tool.Hitbox["sword slash 2"]:Play()
Hitbox:HitStart()
canHit = true
Humanoid.WalkSpeed = 1
wait(config.Cooldown)
Player.Character.Attacking.Value = false
Tool.blade.Trail.Enabled = false
Humanoid.WalkSpeed = 12
Hitbox:HitStop()
canHit = false
de = false
end
end)
\