I need help on adding a feature on this script. It should activate an animation when the NPC hits an humanoid.
r = game:service("RunService")
ching = false
local mobs = script.Parent.Mobs:GetChildren()
for i = 1, #mobs do
function blow(hit)
if ching == true then return end
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid~=nil then
local vCharacter = humanoid.Parent
local vPlayer = game.Players:playerFromCharacter(vCharacter)
dt = Game.Workspace.DynamicText:Clone()
ching = true
print("SWORD HIT")
tagHumanoid(humanoid, vPlayer)
local damage = math.random(mobs[i].SETTINGS.MinDmg.Value,mobs[i].SETTINGS.MaxDmg.Value)
humanoid:TakeDamage(damage)
local part = Instance.new("BillboardGui")
part.Size = UDim2.new(0,50,0,100)
part.StudsOffset = Vector3.new(0,2,0)
local part2 = Instance.new("TextLabel")
part2.FontSize = "Size24"
part2.Font = "ArialBold"
part2.Size = UDim2.new(1,0,1,0)
part2.Position = UDim2.new(0,0,0,0)
part2.BackgroundTransparency = 1
part2.Parent = part
part2.TextStrokeTransparency = 0
dt.Parent = part2
dt.Disabled = false
part.Parent = humanoid.Parent.Head
part.Adornee = part.Parent
if (damage == 0) then
part2.TextColor3 = Color3.new(0/255,102/255,255/255)
part2.Text = ""..damage..""
else
part2.TextColor3 = Color3.new(255/255,0/255,0/255)
part2.Text = "-"..damage..""
end
wait(1)
ching = false
wait(.1)
untagHumanoid(humanoid)
else print("Humanoid does not exist or incorrect humanoid!") --Attempt to make sword unbreakable.
end
end
function tagHumanoid(humanoid, player)
local creator_tag = Instance.new("ObjectValue")
creator_tag.Value = player
creator_tag.Name = "creator"
creator_tag.Parent = humanoid
end
function untagHumanoid(humanoid)
if humanoid ~= nil then
local tag = humanoid:FindFirstChild("creator")
if tag ~= nil then
tag.Parent = nil
end
end
end
mobs[i].Sword.Handle.Touched:connect(blow)
end
