Hello!
I made this script which basically dodges, and damage the player, the problem Is that the NPC sword won't damage the player
Script:
local Noob = script.Parent
local CanDamage = false
while wait(math.random(1,2)) do
local AttackType = math.random(1,4)
if AttackType == 1 then
Noob.SwordSlash:Play()
CanDamage = true
game:GetService("Chat"):Chat(Noob.Head,"Die!",Enum.ChatColor.White)
local AttackSlash = Noob.Humanoid:FindFirstChild("Animator"):LoadAnimation(Noob.Slash)
AttackSlash:Play()
wait(1)
CanDamage = false
end
if AttackType == 2 then
CanDamage = true
Noob.Humanoid.Jump = true
wait(.05)
game:GetService("Chat"):Chat(Noob.Head,"INCOMING!!!",Enum.ChatColor.White)
Noob.SwordLunge:Play()
local VectorForce = Instance.new("VectorForce",Noob.Torso)
local Attachment = Instance.new("Attachment",Noob.Torso)
VectorForce.Attachment0 = Attachment
VectorForce.Force = Vector3.new(0,300,-6000)
VectorForce.ApplyAtCenterOfMass = true
game:GetService("Debris"):AddItem(VectorForce,0.5)
game:GetService("Debris"):AddItem(Attachment,0.5)
local AttackSlash = Noob.Humanoid:FindFirstChild("Animator"):LoadAnimation(Noob.Lunge)
AttackSlash:Play()
wait(1)
CanDamage = false
end
if AttackType == 3 then
CanDamage = true
Noob.Humanoid.Jump = true
wait(.05)
game:GetService("Chat"):Chat(Noob.Head,"Skill Issue XD",Enum.ChatColor.White)
local VectorForce = Instance.new("VectorForce",Noob.Torso)
local Attachment = Instance.new("Attachment",Noob.Torso)
VectorForce.Attachment0 = Attachment
VectorForce.Force = Vector3.new(6000,300,0)
VectorForce.ApplyAtCenterOfMass = true
game:GetService("Debris"):AddItem(VectorForce,0.5)
game:GetService("Debris"):AddItem(Attachment,0.5)
end
if AttackType == 4 then
CanDamage = true
Noob.Humanoid.Jump = true
wait(.05)
game:GetService("Chat"):Chat(Noob.Head,"You hate me already? Admit It!",Enum.ChatColor.White)
local VectorForce = Instance.new("VectorForce",Noob.Torso)
local Attachment = Instance.new("Attachment",Noob.Torso)
VectorForce.Attachment0 = Attachment
VectorForce.Force = Vector3.new(-6000,300,0)
VectorForce.ApplyAtCenterOfMass = true
game:GetService("Debris"):AddItem(VectorForce,0.5)
game:GetService("Debris"):AddItem(Attachment,0.5)
end
end
Noob.Sword.Touched:Connect(function(hit)
local Humanoid = hit.Parent:WaitForChild("Humanoid")
if Humanoid and CanDamage == true then
Noob["Sword Stab"]:Play()
Humanoid:TakeDamage(30)
CanDamage = false
end
end)
