So i have an npc that shoots and can kill me but when i get his health bar to 0 he doesnt die.Can anyone help me?
-Also i did make a video but it said i couldnt use it so yeah
So i have an npc that shoots and can kill me but when i get his health bar to 0 he doesnt die.Can anyone help me?
-Also i did make a video but it said i couldnt use it so yeah
What do you exactly mean by âdieâ? Do you mean you want the limbs to fall off the NPC, or do you want the NPC to disappear after it has died?
Can you send your script, and the layout of the workspace?
for _, childPart in pairs(config:GetChildren()) do
if (childPart:IsA("Animation")) then
table.insert(animTable[name].connections, childPart.Changed:connect(function(property) configureAnimationSet(name, fileList) end))
animTable[name][idx] = {}
animTable[name][idx].anim = childPart
local weightObject = childPart:FindFirstChild("Weight")
if (weightObject == nil) then
animTable[name][idx].weight = 1
else
animTable[name][idx].weight = weightObject.Value
end
animTable[name].count = animTable[name].count + 1
animTable[name].totalWeight = animTable[name].totalWeight + animTable[name][idx].weight
-- print(name .. " [" .. idx .. "] " .. animTable[name][idx].anim.AnimationId .. " (" .. animTable[name][idx].weight .. ")")
idx = idx + 1
end
end
end
-- fallback to defaults
if (animTable[name].count <= 0) then
for idx, anim in pairs(fileList) do
animTable[name][idx] = {}
animTable[name][idx].anim = Instance.new("Animation")
animTable[name][idx].anim.Name = name
animTable[name][idx].anim.AnimationId = anim.id
animTable[name][idx].weight = anim.weight
animTable[name].count = animTable[name].count + 1
animTable[name].totalWeight = animTable[name].totalWeight + anim.weight
â print(name ⌠" [" ⌠idx ⌠â] " ⌠anim.id ⌠" (â ⌠anim.weight ⌠â)â)
end
end
end
â Setup animation objects
function scriptChildModified(child)
local fileList = animNames[child.Name]
if (fileList ~= nil) then
configureAnimationSet(child.Name, fileList)
end
end
script.ChildAdded:connect(scriptChildModified)
script.ChildRemoved:connect(scriptChildModified)
for name, fileList in pairs(animNames) do
configureAnimationSet(name, fileList)
end
â ANIMATION
â declarations
local toolAnim = âNoneâ
local toolAnimTime = 0
local jumpAnimTime = 0
local jumpAnimDuration = 0.3
local toolTransitionTime = 0.1
local fallTransitionTime = 0.3
local jumpMaxLimbVelocity = 0.75
â functions
function stopAllAnimations()
local oldAnim = currentAnim
-- return to idle if finishing an emote
if (emoteNames[oldAnim] ~= nil and emoteNames[oldAnim] == false) then
oldAnim = "idle"
end
currentAnim = ""
currentAnimInstance = nil
if (currentAnimKeyframeHandler ~= nil) then
currentAnimKeyframeHandler:disconnect()
end
if (currentAnimTrack ~= nil) then
currentAnimTrack:Stop()
currentAnimTrack:Destroy()
currentAnimTrack = nil
end
return oldAnim
end
function setAnimationSpeed(speed)
if speed ~= currentAnimSpeed then
currentAnimSpeed = speed
currentAnimTrack:AdjustSpeed(currentAnimSpeed)
end
end
function keyFrameReachedFunc(frameName)
if (frameName == âEndâ) then
local repeatAnim = currentAnim
-- return to idle if finishing an emote
if (emoteNames[repeatAnim] ~= nil and emoteNames[repeatAnim] == false) then
repeatAnim = "idle"
end
local animSpeed = currentAnimSpeed
playAnimation(repeatAnim, 0.0, Humanoid)
setAnimationSpeed(animSpeed)
end
end
â Preload animations
function playAnimation(animName, transitionTime, humanoid)
local roll = math.random(1, animTable[animName].totalWeight)
local origRoll = roll
local idx = 1
while (roll > animTable[animName][idx].weight) do
roll = roll - animTable[animName][idx].weight
idx = idx + 1
end
â print(animName ⌠" " ⌠idx ⌠" [" ⌠origRoll ⌠â]â)
local anim = animTable[animName][idx].anim
-- switch animation
if (anim ~= currentAnimInstance) then
if (currentAnimTrack ~= nil) then
currentAnimTrack:Stop(transitionTime)
currentAnimTrack:Destroy()
end
currentAnimSpeed = 1.0
-- load it to the humanoid; get AnimationTrack
currentAnimTrack = humanoid:LoadAnimation(anim)
currentAnimTrack.Priority = Enum.AnimationPriority.Core
-- play the animation
currentAnimTrack:Play(transitionTime)
currentAnim = animName
currentAnimInstance = anim
-- set up keyframe name triggers
if (currentAnimKeyframeHandler ~= nil) then
currentAnimKeyframeHandler:disconnect()
end
currentAnimKeyframeHandler = currentAnimTrack.KeyframeReached:connect(keyFrameReachedFunc)
end
end
local toolAnimName = ââ
local toolAnimTrack = nil
local toolAnimInstance = nil
local currentToolAnimKeyframeHandler = nil
function toolKeyFrameReachedFunc(frameName)
if (frameName == âEndâ) then
â print("Keyframe : "⌠frameName)
playToolAnimation(toolAnimName, 0.0, Humanoid)
end
end
function playToolAnimation(animName, transitionTime, humanoid, priority)
local roll = math.random(1, animTable[animName].totalWeight)
local origRoll = roll
local idx = 1
while (roll > animTable[animName][idx].weight) do
roll = roll - animTable[animName][idx].weight
idx = idx + 1
end
â print(animName ⌠" * " ⌠idx ⌠" [" ⌠origRoll ⌠â]â)
local anim = animTable[animName][idx].anim
if (toolAnimInstance ~= anim) then
if (toolAnimTrack ~= nil) then
toolAnimTrack:Stop()
toolAnimTrack:Destroy()
transitionTime = 0
end
-- load it to the humanoid; get AnimationTrack
toolAnimTrack = humanoid:LoadAnimation(anim)
if priority then
toolAnimTrack.Priority = priority
end
-- play the animation
toolAnimTrack:Play(transitionTime)
toolAnimName = animName
toolAnimInstance = anim
currentToolAnimKeyframeHandler = toolAnimTrack.KeyframeReached:connect(toolKeyFrameReachedFunc)
end
end
function stopToolAnimations()
local oldAnim = toolAnimName
if (currentToolAnimKeyframeHandler ~= nil) then
currentToolAnimKeyframeHandler:disconnect()
end
toolAnimName = ""
toolAnimInstance = nil
if (toolAnimTrack ~= nil) then
toolAnimTrack:Stop()
toolAnimTrack:Destroy()
toolAnimTrack = nil
end
return oldAnim
end
function onRunning(speed)
if speed > 0.01 then
playAnimation(âwalkâ, 0.1, Humanoid)
if currentAnimInstance and currentAnimInstance.AnimationId == âhttp://www.roblox.com/asset/?id=180426354â then
setAnimationSpeed(speed / 14.5)
end
pose = âRunningâ
else
if emoteNames[currentAnim] == nil then
playAnimation(âidleâ, 0.1, Humanoid)
pose = âStandingâ
end
end
end
function onDied()
pose = âDeadâ
end
function onJumping()
playAnimation(âjumpâ, 0.1, Humanoid)
jumpAnimTime = jumpAnimDuration
pose = âJumpingâ
end
function onClimbing(speed)
playAnimation(âclimbâ, 0.1, Humanoid)
setAnimationSpeed(speed / 12.0)
pose = âClimbingâ
end
function onGettingUp()
pose = âGettingUpâ
end
function onFreeFall()
if (jumpAnimTime <= 0) then
playAnimation(âfallâ, fallTransitionTime, Humanoid)
end
pose = âFreeFallâ
end
function onFallingDown()
pose = âFallingDownâ
end
function onSeated()
pose = âSeatedâ
end
function onPlatformStanding()
pose = âPlatformStandingâ
end
function onSwimming(speed)
if speed > 0 then
pose = âRunningâ
else
pose = âStandingâ
end
end
function getTool()
for _, kid in ipairs(Figure:GetChildren()) do
if kid.className == âToolâ then return kid end
end
return nil
end
function getToolAnim(tool)
for _, c in ipairs(tool:GetChildren()) do
if c.Name == âtoolanimâ and c.className == âStringValueâ then
return c
end
end
return nil
end
function animateTool()
if (toolAnim == "None") then
playToolAnimation("toolnone", toolTransitionTime, Humanoid, Enum.AnimationPriority.Idle)
return
end
if (toolAnim == "Slash") then
playToolAnimation("toolslash", 0, Humanoid, Enum.AnimationPriority.Action)
return
end
if (toolAnim == "Lunge") then
playToolAnimation("toollunge", 0, Humanoid, Enum.AnimationPriority.Action)
return
end
end
function moveSit()
RightShoulder.MaxVelocity = 0.15
LeftShoulder.MaxVelocity = 0.15
RightShoulder:SetDesiredAngle(3.14 /2)
LeftShoulder:SetDesiredAngle(-3.14 /2)
RightHip:SetDesiredAngle(3.14 /2)
LeftHip:SetDesiredAngle(-3.14 /2)
end
local lastTick = 0
function move(time)
local amplitude = 1
local frequency = 1
local deltaTime = time - lastTick
lastTick = time
local climbFudge = 0
local setAngles = false
if (jumpAnimTime > 0) then
jumpAnimTime = jumpAnimTime - deltaTime
end
if (pose == "FreeFall" and jumpAnimTime <= 0) then
playAnimation("fall", fallTransitionTime, Humanoid)
elseif (pose == "Seated") then
playAnimation("sit", 0.5, Humanoid)
return
elseif (pose == "Running") then
playAnimation("walk", 0.1, Humanoid)
elseif (pose == "Dead" or pose == "GettingUp" or pose == "FallingDown" or pose == "Seated" or pose == "PlatformStanding") then
â print("Wha " ⌠pose)
stopAllAnimations()
amplitude = 0.1
frequency = 1
setAngles = true
end
if (setAngles) then
local desiredAngle = amplitude * math.sin(time * frequency)
RightShoulder:SetDesiredAngle(desiredAngle + climbFudge)
LeftShoulder:SetDesiredAngle(desiredAngle - climbFudge)
RightHip:SetDesiredAngle(-desiredAngle)
LeftHip:SetDesiredAngle(-desiredAngle)
end
-- Tool Animation handling
local tool = getTool()
if tool and tool:FindFirstChild("Handle") then
local animStringValueObject = getToolAnim(tool)
if animStringValueObject then
toolAnim = animStringValueObject.Value
-- message recieved, delete StringValue
animStringValueObject.Parent = nil
toolAnimTime = time + .3
end
if time > toolAnimTime then
toolAnimTime = 0
toolAnim = "None"
end
animateTool()
else
stopToolAnimations()
toolAnim = "None"
toolAnimInstance = nil
toolAnimTime = 0
end
end
â connect events
Humanoid.Died:connect(onDied)
Humanoid.Running:connect(onRunning)
Humanoid.Jumping:connect(onJumping)
Humanoid.Climbing:connect(onClimbing)
Humanoid.GettingUp:connect(onGettingUp)
Humanoid.FreeFalling:connect(onFreeFall)
Humanoid.FallingDown:connect(onFallingDown)
Humanoid.Seated:connect(onSeated)
Humanoid.PlatformStanding:connect(onPlatformStanding)
Humanoid.Swimming:connect(onSwimming)
â setup emote chat hook
â[[game:GetService(âPlayersâ).LocalPlayer.Chatted:connect(function(msg)
local emote = ââ
if msg == â/e danceâ then
emote = dances[math.random(1, #dances)]
elseif (string.sub(msg, 1, 3) == "/e ") then
emote = string.sub(msg, 4)
elseif (string.sub(msg, 1, 7) == "/emote ") then
emote = string.sub(msg, 8)
end
if (pose == "Standing" and emoteNames[emote] ~= nil) then
playAnimation(emote, 0.1, Humanoid)
end
end)â]]
â main program
â initialize to idle
playAnimation(âidleâ, 0.1, Humanoid)
pose = âStandingâ
while Figure.Parent ~= nil do
local _, time = wait(0.1)
move(time)
end
???
Can you send it correctly, wrappedâŚ
my other script is
for i,v in ipairs(script.Parent:GetDescendants()) do
if v:IsA(âBasePartâ) and v:CanSetNetworkOwnership() == true then
v:SetNetworkOwner(nil)
end
end
âBody Variables
local myHuman = script.Parent:WaitForChild(âHumanoidâ)
local myTorso = script.Parent:WaitForChild(âTorsoâ)
local myHead = script.Parent:WaitForChild(âHeadâ)
local neck = myTorso:WaitForChild(âNeckâ)
local headWeld = myTorso:WaitForChild(âHead Weldâ)
local rArm = script.Parent:WaitForChild(âRight Armâ)
local lArm = script.Parent:WaitForChild(âLeft Armâ)
local lShoulder = myTorso:WaitForChild(âLeft Shoulderâ)
local rShoulder = myTorso:WaitForChild(âRight Shoulderâ)
local lArmWeld = myTorso:WaitForChild(âLeft Arm Weldâ)
local rArmWeld = myTorso:WaitForChild(âRight Arm Weldâ)
âM4 Variables
local m4 = script.Parent:WaitForChild(âM4â)
local m4Weld = m4:WaitForChild(âM4 Weldâ)
local barrel = script.Parent:WaitForChild(âBarrelâ)
local aimer = script.Parent:WaitForChild(âAimerâ)
local aimerWeld = aimer:WaitForChild(âAimer Weldâ)
âKnife variables
local knife = script.Parent:WaitForChild(âKnifeâ)
local knifeWeld = knife:WaitForChild(âKnife Weldâ)
âGrenade variables
local grenade = script.Parent.Grenade
âSounds
local equipSound = m4:WaitForChild(âEquipâ)
local fireSound = m4:WaitForChild(âFireâ)
local reloadSound = m4:WaitForChild(âReloadâ)
local knifeEquipSound = knife:WaitForChild(âEquipSoundâ)
local knifeAttackSound = knife:WaitForChild(âAttackSoundâ)
local knifeStabSound = knife:WaitForChild(âStabSoundâ)
local hurtSound = myHead:WaitForChild(âHurtâ)
local pinSound = grenade.Pin
âAnimations
local stabAnimation = myHuman:LoadAnimation(script.Parent.Stab)
stabAnimation.Priority = Enum.AnimationPriority.Action
local throwAnimation = myHuman:LoadAnimation(script.Parent.ThrowAnimation)
throwAnimation.Priority = Enum.AnimationPriority.Action
throwAnimation.Looped = false
local reloadAnimation = myHuman:LoadAnimation(script.Parent.Reload)
reloadAnimation.Priority = Enum.AnimationPriority.Action
local reloading = false
local weaponAimed = false
local weaponCool = true
local m4Equipped = false
local knifeEquipped = false
local grenadeCool = true
local fullMag = 30
local mag = fullMag
local allies = {script.Parent.Name,âCivilianâ}
local potentialTargets = {}
local activeAllies = {}
function checkDist(part1,part2)
return (part1.Position - part2.Position).Magnitude
end
function checkSight(target)
local ray = Ray.new(barrel.Position, (target.Position - barrel.Position).Unit * 150)
local part,position = workspace:FindPartOnRayWithIgnoreList(ray, {script.Parent})
local ray2 = Ray.new(myTorso.Position, (target.Position - myTorso.Position).Unit * 150)
local part2,position2 = workspace:FindPartOnRayWithIgnoreList(ray2, {script.Parent})
if part and part2 then
if part:IsDescendantOf(target.Parent) and part2:IsDescendantOf(target.Parent) then
return true
end
end
return false
end
function findTarget()
local dist = 600
local target = nil
potentialTargets = {}
local seeTargets = {}
for _,v in ipairs(workspace:GetChildren()) do
local human = v:FindFirstChild(âHumanoidâ)
local torso = v:FindFirstChild(âTorsoâ) or v:FindFirstChild(âHumanoidRootPartâ)
if human and torso and v ~= script.Parent then
if (myTorso.Position - torso.Position).magnitude < dist and human.Health > 0 then
for i,x in ipairs(allies) do
if x == v.Name then
table.insert(activeAllies,torso)
break
elseif i == #allies then
table.insert(potentialTargets,torso)
end
end
end
end
end
if #potentialTargets > 0 then
for i,v in ipairs(potentialTargets) do
if checkSight(v) then
table.insert(seeTargets,v)
end
end
if #seeTargets > 0 then
for i,v in ipairs(seeTargets) do
if (myTorso.Position - v.Position).magnitude < dist then
target = v
dist = (myTorso.Position - v.Position).magnitude
end
end
else
for i,v in ipairs(potentialTargets) do
if (myTorso.Position - v.Position).magnitude < dist then
target = v
dist = (myTorso.Position - v.Position).magnitude
end
end
end
end
return target
end
function pathToLocation(target)
local path = game:GetService(âPathfindingServiceâ):CreatePath()
path:ComputeAsync(myTorso.Position, target.Position)
local waypoints = path:GetWaypoints()
for _,waypoint in ipairs(waypoints) do
if waypoint.Action == Enum.PathWaypointAction.Jump then
myHuman.Jump = true
end
myHuman:MoveTo(waypoint.Position)
delay(0.5,function()
if myHuman.WalkToPoint.Y > myTorso.Position.Y then
myHuman.Jump = true
end
end)
local moveSuccess = myHuman.MoveToFinished:Wait()
if not moveSuccess or checkSight(target) then
break
end
end
end
function walkRandom()
local randX = math.random(-100,100)
local randZ = math.random(-100,100)
local goal = myTorso.Position + Vector3.new(randX, 0, randZ)
local path = game:GetService(âPathfindingServiceâ):CreatePath()
path:ComputeAsync(myTorso.Position, goal)
local waypoints = path:GetWaypoints()
if path.Status == Enum.PathStatus.Success then
for i,waypoint in ipairs(waypoints) do
if waypoint.Action == Enum.PathWaypointAction.Jump then
myHuman.Jump = true
end
myHuman:MoveTo(waypoint.Position)
delay(0.5,function()
if myHuman.WalkToPoint.Y > myTorso.Position.Y then
myHuman.Jump = true
end
end)
local moveSuccess = myHuman.MoveToFinished:Wait()
if not moveSuccess then
break
end
if i % 5 == 0 then
if findTarget() then
break
end
end
end
else
wait(2)
end
end
function drawM4()
yieldKnife()
if m4Equipped == false then
m4Equipped = true
equipSound:Play()
--Right Arm Setup
rShoulder.Part1 = nil
rArm.CFrame = aimer.CFrame * CFrame.new(1.25,0.05,-0.65) * CFrame.Angles(math.rad(80),math.rad(0),math.rad(-10))
rArmWeld.Part1 = rArm
--Left Arm Setup
lShoulder.Part1 = nil
lArm.CFrame = aimer.CFrame * CFrame.new(-0.35,0.05,-1.48) * CFrame.Angles(math.rad(84),math.rad(-3),math.rad(28))
lArmWeld.Part1 = lArm
--M4 Setup
m4Weld.Part0 = nil
m4.CFrame = aimer.CFrame * CFrame.new(0.65,0.6,-2.22) * CFrame.Angles(math.rad(0),math.rad(0),math.rad(0))
m4Weld.Part0 = aimer
end
end
function yieldM4()
if weaponAimed == true then
weaponAimed = false
resetHead()
end
if m4Equipped == true then
m4Equipped = false
equipSound:Play()
--Right Arm setup
rArmWeld.Part1 = nil
rShoulder.Part1 = rArm
--Left Arm Setup
lArmWeld.Part1 = nil
lShoulder.Part1 = lArm
--M4 Setup
m4Weld.Part0 = nil
m4.CFrame = myTorso.CFrame * CFrame.new(0,0,0.6) * CFrame.Angles(math.rad(-90),math.rad(-60),math.rad(90))
m4Weld.Part0 = myTorso
end
end
function drawKnife()
yieldM4()
if knifeEquipped == false then
knifeEquipSound:Play()
knifeEquipped = true
knifeWeld.Part0 = nil
knife.CFrame = rArm.CFrame * CFrame.new(0,-1,-1) * CFrame.Angles(math.rad(90),math.rad(180),math.rad(180))
knifeWeld.Part0 = rArm
end
end
function yieldKnife()
if knifeEquipped == true then
knifeEquipped = false
knifeWeld.Part0 = nil
knife.CFrame = myTorso.CFrame * CFrame.new(-1,-1,0.5) * CFrame.Angles(math.rad(-65),0,math.rad(180))
knifeWeld.Part0 = myTorso
end
end
function aim(target)
if weaponAimed == false then
neck.C0 = neck.C0 * CFrame.Angles(0,math.rad(-15),0)
end
weaponAimed = true
for i=0,1,0.1 do
wait()
local look = Vector3.new(target.Position.X,myTorso.Position.Y,target.Position.Z)
myTorso.CFrame = myTorso.CFrame:Lerp(CFrame.new(myTorso.Position,look),i)
if reloading == false then
aimerWeld.Part1 = nil
aimer.CFrame = aimer.CFrame:Lerp(CFrame.new((myTorso.CFrame * CFrame.new(0,0.5,0)).p,target.Position),i)
aimerWeld.Part1 = aimer
neck.C0 = CFrame.new(0,1,0) * CFrame.Angles(-1.5 + math.rad(aimer.Orientation.X),math.rad(15),math.rad(180))
end
end
end
function resetHead()
game:GetService(âTweenServiceâ):Create(neck,TweenInfo.new(0.2),{C0 = CFrame.new(0,1,0) * CFrame.Angles(math.rad(-90),0,math.rad(180))}):Play()
end
function shoot(target)
if weaponCool == true and reloading == false then
weaponCool = false
local shot
if checkDist(target,myTorso) > 60 then
shot = 1
else
shot = 3
end
for i = 1, shot do
wait(0.1)
mag = mag - 1
local flash = Instance.new("PointLight",barrel)
flash.Brightness = 3
game:GetService("Debris"):AddItem(flash,0.1)
local bullet = Instance.new("Part")
bullet.Size = Vector3.new(0.1,0.1,0.3)
bullet.BrickColor = BrickColor.new("Gold")
bullet.Material = Enum.Material.Neon
bullet.CFrame = barrel.CFrame
bullet.CanCollide = false
bullet.Touched:Connect(function(obj)
if not obj:IsDescendantOf(script.Parent) then
local human = obj.Parent:FindFirstChild("Humanoid")
if human then
if obj.Name == "Head" then
human:TakeDamage(100)
else
human:TakeDamage(math.random(30,40))
end
end
bullet:Destroy()
end
end)
bullet.Parent = workspace
fireSound:Play()
local spread = Vector3.new(math.random(-shot,shot)/100,math.random(-shot,shot)/100,math.random(-shot,shot)/100)
local bv = Instance.new("BodyVelocity",bullet)
bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bv.Velocity = (aimer.CFrame.LookVector + spread) * 300
local s = Instance.new("Sound",bullet)
s.Volume = 0.7
s.PlaybackSpeed = 7
s.Looped = true
s.SoundId = "rbxassetid://4872110675"
s:Play()
local a1 = Instance.new("Attachment",bullet)
a1.Position = Vector3.new(0,0.05,0)
local a2 = Instance.new("Attachment",bullet)
a2.Position = Vector3.new(0,-0.05,0)
local t = Instance.new("Trail",bullet)
t.Attachment0 = a1
t.Attachment1 = a2
t.Color = ColorSequence.new(bullet.Color)
t.WidthScale = NumberSequence.new(0.1,0.01)
t.Lifetime = 0.3
aimerWeld.Part1 = nil
aimer.CFrame = aimer.CFrame * CFrame.Angles(math.rad(math.random(1,4)/4),0,0)
aimerWeld.Part1 = aimer
game:GetService("Debris"):AddItem(bullet, 5)
end
if mag <= 0 then
reload()
end
delay(1, function()
weaponCool = true
end)
end
end
function reload()
if weaponAimed == true then
resetHead()
weaponAimed = false
end
reloadSound:Play()
reloading = true
yieldM4()
m4Weld.Part0 = nil
m4.CFrame = lArm.CFrame * CFrame.new(0.6,-1.3,0.2) * CFrame.Angles(math.rad(180),0,0)
m4Weld.Part0 = lArm
reloadAnimation:Play()
reloadAnimation:AdjustSpeed(3)
reloadAnimation.Stopped:Wait()
reloading = false
mag = fullMag
drawM4()
end
function stab(target)
if weaponCool == true then
weaponCool = false
knifeStabSound:Play()
knifeAttackSound:Play()
stabAnimation:Play()
local human = target.Parent.Humanoid
human:TakeDamage(math.random(30,50))
if human.Health <= 0 then
wait(0.2)
end
delay(0.5,function()
weaponCool = true
end)
end
end
function yieldWeapons()
yieldKnife()
yieldM4()
if weaponAimed == true then
weaponAimed = false
resetHead()
end
end
function checkCluster(target)
âCheck for nearby allies
for i,v in ipairs(activeAllies) do
if checkDist(target,v) < 30 then
return false
end
end
âCheck if enemies are paired close together
for i,v in ipairs(potentialTargets) do
if v ~= target then
if checkDist(target,v) < 15 then
return true
end
end
end
return false
end
function throwGrenade(target)
if weaponCool == true and grenadeCool == true then
weaponCool = false
grenadeCool = false
yieldWeapons()
local g = grenade:Clone()
g.Boom.PlayOnRemove = true
g.Parent = workspace
g.CanCollide = true
g.CFrame = rArm.CFrame * CFrame.new(0,-1.3,0) * CFrame.Angles(0,0,math.rad(90))
game:GetService(âDebrisâ):AddItem(g,5)
grenade.Transparency = 1
local w = Instance.new("WeldConstraint",g)
w.Part0 = rArm
w.Part1 = g
throwAnimation:Play()
pinSound:Play()
aim(target)
wait(0.4)
if myHuman.Health <= 0 then
return
end
aim(target)
throwAnimation:Stop()
w.Part1 = nil
local dist = checkDist(myTorso,target)
g.Velocity = (myTorso.CFrame.LookVector + Vector3.new(0,1,0)) * Vector3.new(dist,dist*1.5,dist)
--Wait until grenade is thrown before it can be primed
touched = g.Touched:Connect(function(obj)
if not obj:IsDescendantOf(script.Parent) then
touched:Disconnect()
g.Pin:Play()
wait(0.5)
local x = Instance.new("Explosion",workspace)
x.Position = g.Position
x.Hit:Connect(function(obj,dist)
local human = obj.Parent:FindFirstChild("Humanoid")
if human then
human:TakeDamage(20 - dist)
human:ChangeState(Enum.HumanoidStateType.Ragdoll)
end
end)
g:Destroy()
game:GetService("Debris"):AddItem(x,2)
end
end)
local attach0 = g.Attach0
local attach1 = g.Attach1
local t = Instance.new("Trail",g)
t.Attachment0 = attach0
t.Attachment1 = attach1
t.Lifetime = 0.5
t.Color = ColorSequence.new(Color3.fromRGB(150,150,150))
t.WidthScale = NumberSequence.new(1,0)
delay(1,function()
weaponCool = true
wait(5)
grenadeCool = true
grenade.Transparency = 0
end)
end
end
function main()
local target = findTarget()
if target then
if checkSight(target) then
if checkDist(myTorso,target) > 15 then
if checkCluster(target) == true and checkDist(target,myTorso) < 100 and checkDist(target,myTorso) > 30 and grenadeCool == true then
throwGrenade(target)
else
drawM4()
aim(target)
shoot(target)
end
else
drawKnife()
myHuman:MoveTo(target.Position)
if checkDist(target,myTorso) < 7 then
stab(target)
end
end
else
if weaponAimed == true then
weaponAimed = false
resetHead()
spawn(function()
for i=0,1,0.1 do
wait()
aimerWeld.Part1 = nil
aimer.CFrame = myTorso.CFrame * CFrame.new(0,0.5,0) * CFrame.Angles(math.rad(-35),0,0)
aimerWeld.Part1 = aimer
if weaponAimed then
break
end
end
end)
end
pathToLocation(target)
end
else
yieldWeapons()
walkRandom()
end
end
function Died()
for i,v in ipairs(script.Parent:GetDescendants()) do
if v:IsA(âBallSocketConstraintâ) then
v.Enabled = true
elseif v:IsA(âBasePartâ) and v.Name ~= âHumanoidRootPartâ and v ~= aimer then
v.CanCollide = false
elseif v:IsA(âMotor6Dâ) then
v:Destroy()
end
end
wait(10)
for i,v in ipairs(script.Parent:GetDescendants()) do
if v:IsA(âBasePartâ) or v:IsA(âDecalâ) then
game:GetService(âTweenServiceâ):Create(v,TweenInfo.new(0.2),{Transparency = 1}):Play()
end
end
wait(0.2)
clone.Parent = workspace
script.Parent:Destroy()
end
myHuman.Died:Connect(Died)
local oldHealth = myHuman.Health
local soundSpeeds = {0.9,0.95,1,1.05,1.1}
myHuman.HealthChanged:Connect(function(health)
if health < oldHealth and hurtSound.IsPlaying == false then
hurtSound.PlaybackSpeed = soundSpeeds[math.random(#soundSpeeds)]
hurtSound:Play()
end
oldHealth = health
end)
while wait() do
if myHuman.Health > 0 then
main()
else
break
end
end
like a photo of the script???
No⌠look at the way your doing it
Some of it is inside, and some isnâtâŚ
Also can you just send the part where uh, the problem isâŚ
I donât really think anyone really would wanna read all that code.
So I assume that âdoesnât diesâ meaning that after your npcâs Humanoid.Health is < 0 (which means the npc dead fr) it still can shoot the player and damage the player. For this type of problem, I suggest that you go recheck on the part of your script that is responsible for the shooting and damaging the player, and set up a stop boolean to prevent the NPC to keep firing at the player when it dies:
--set up the dead variable
local Dead = false -- keeping it false for now cause you don't want it to start right at the moment you join the game
if not Dead then -- only runs whenever the Humanoid of That NPC is alive
--The Whole Shooting/ Find Target/ Damaging... Script Part, whatever function that you don't want them to run when the NPC is dead
end
function onDied()
pose = âDeadâ
Dead = true --set it to true
end
â connect events
Humanoid.Died:connect(onDied)