With 30 minutes of testing with various Vector3 multipliers and CFrame angles, I finally fixed it. Here’s the code:
local npc = script.Parent
local remote = npc:WaitForChild('InputHandler')
local Enraged = npc:WaitForChild('Enraged')
local Eyes = npc:WaitForChild('Eyes')
local ragdoll1 = script:WaitForChild('R6Ragdoll')
local ragdoll2 = script:WaitForChild('R15Ragdoll')
local blood = npc:WaitForChild('Blood')
local sword = npc:WaitForChild('Sword')
local ts = game:GetService('TweenService')
local sworddebounce = false
local swordcooldown = 1.5
local swordSpeed = 100
local runval = npc:WaitForChild('Running')
local Ouch = npc.Head:WaitForChild('Ouch')
local speedLight = npc.Torso:WaitForChild('Speed')
local speedSparks = npc.Torso:WaitForChild('Sparks')
remote.OnServerEvent:Connect(function(Player,Sound,Mode,mouseHit)
if Player.Name ~= npc.Player.Value then return end
if Mode == nil then
Sound:Play()
elseif Mode == 'Enraged' then
Enraged.Value = not Enraged.Value
if Enraged.Value == true then
Sound:Play()
Eyes.Transparency = .5
Eyes.PointLight.Enabled = true
else
for i = .5,2,.05 do
Eyes.Transparency = i
end
Eyes.PointLight.Enabled = false
end
elseif Mode == 'Sword' then
if sworddebounce == true then return end
sworddebounce = true
spawn(function()
task.wait(swordCooldown)
sworddebounce = false
end)
local swordd = sword:Clone()
swordd.Parent = workspace
swordd.Anchored = true
swordd.Transparency = 0
swordd.CFrame = CFrame.new(npc.Torso.Position + Vector3.new(0,3,0))
swordd.CFrame = CFrame.lookAt(swordd.Position, mouseHit) * CFrame.Angles(0,math.rad(180),math.rad(180))
local params = RaycastParams.new()
local iterations = 100
params.FilterDescendantsInstances = {npc,swordd}
params.FilterType = Enum.RaycastFilterType.Blacklist
local bulletConnection
swordd.SwordLunge:Play()
bulletConnection = game:GetService('RunService').Heartbeat:Connect(function(deltaTime)
local position,nextPosition = swordd.Position, (swordd.CFrame.LookVector * Vector3.new(-1,-1,-1)) * deltaTime * swordSpeed
local result = workspace:Raycast(position,nextPosition,params)
if result then
swordd.SwordSlash:Play()
bulletConnection:Disconnect()
local model = result.Instance:FindFirstAncestorOfClass('Model')
local human = nil
if model then human = model:FindFirstChildOfClass('Humanoid') end
if human and human.Health > 0 then
local clone = Ouch:Clone()
clone.Parent = model:FindFirstChild('Head')
clone:Play()
if result.Instance.Name:find('Leg') then
human.WalkSpeed -=2.5
human:TakeDamage(math.random(10,30))
elseif result.Instance.Name:find('Torso') then
human:TakeDamage(math.random(20,30))
human.WalkSpeed -=3
elseif result.Instance.Name == 'Head' then
human:TakeDamage(30)
elseif result.Instance.Name:find('Arm') then
human:TakeDamage(math.random(10,30))
end
spawn(function()
local blclone = blood:Clone()
blclone.Parent = result.Instance
blclone.Enabled = true
task.wait(.3)
blclone:Destroy()
end)
swordd.Position = result.Position
swordd.Parent = result.Instance
local weld = Instance.new('WeldConstraint')
weld.Part0 = swordd
weld.Part1 = result.Instance
weld.Parent = swordd
weld.Enabled = true
swordd.Anchored = false
spawn(function()
task.wait(10)
swordd:Destroy()
end)
else
swordd.Position = result.Position
swordd.Parent = result.Instance
local weld = Instance.new('WeldConstraint')
weld.Part0 = swordd
weld.Part1 = result.Instance
weld.Parent = swordd
weld.Enabled = true
swordd.Anchored = false
spawn(function()
task.wait(10)
swordd:Destroy()
end)
end
else
swordd.Position = position + nextPosition
end
iterations -= 1
if iterations < 0 then
bulletConnection:Disconnect()
swordd:Destroy()
end
end)
elseif Mode == 'Speed' then
runval.Value = not runval.Value
if runval.Value == true then
npc.Humanoid.WalkSpeed = 35
speedLight.Enabled = true
speedSparks.Enabled = true
else
npc.Humanoid.WalkSpeed = 16
speedLight.Enabled = false
speedSparks.Enabled = false
end
end
end)
for _,v in pairs(npc:GetChildren()) do
if v:IsA('Part') then
v.Touched:Connect(function(obj)
if Enraged.Value ~= true then return end
local model = obj:FindFirstAncestorOfClass('Model')
if model then
local hum = model:FindFirstChildOfClass('Humanoid')
if hum and hum ~= npc.Humanoid and hum.Health ~= 0 then
hum:TakeDamage(1)
spawn(function()
local blclone = blood:Clone()
blclone.Parent = obj
blclone.Enabled = true
task.wait(.3)
blclone:Destroy()
end)
if hum.Health == 0 then
local clone = Ouch:Clone()
clone.Parent = model:FindFirstChild('Head')
clone:Play()
if model:FindFirstChild('UpperTorso') then
local clone = ragdoll2:Clone()
clone.Parent = model
clone.Disabled = false
local bloodclone = blood:Clone()
bloodclone.Parent = model:FindFirstChild('UpperTorso')
bloodclone.Enabled = true
else
local clone = ragdoll1:Clone()
clone.Parent = model
clone.Disabled = false
local bloodclone = blood:Clone()
bloodclone.Parent = model:FindFirstChild('Torso')
bloodclone.Enabled = true
end
end
end
end
end)
end
end
The solution was to flip the swords direction, but also flip the moving direction as well. I also added a variable for the sword throw cooldown for easier tinkering. Have a nice day!