I’ve been stuck on my script quite a while now and tried to do various thing’s to make it work but none came out positive. I am trying to make the script stop/disable when the NPC finally kills the player.
I tried to use a disabled clone of the script then destroying the old one and I tried Indentation.
My Entire Script: (Sorry if it looks weirdly organised this is just how I like the way my scripts look)
--ANIMATION
local Animations = {
"rbxassetid://4527091153","rbxassetid://4527084389","rbxassetid://4527075451"
}
local Animation = Animations[math.random(1,#Animations)]
script.Parent.Animation.AnimationId = Animation
local hum = script.Parent.Parent.Humanoid
local anim = hum:LoadAnimation((script.Parent.Animation))
--SOUND
local Sounds = {
"rbxassetid://3211793636","rbxassetid://338586299"
}
local Sound = Sounds[math.random(1,#Sounds)]
local SwingSound = script.Parent.SwordSwing
local SwordHit = script.Parent.SwordHit
SwingSound.SoundId = Sound
local IsHum = script.Parent.Parent:FindFirstChildOfClass("Humanoid")
local CanDamage = script.Parent.Parent:WaitForChild("CanDamage")
script.Parent.Touched:Connect(function(hit)
if hit and hit.Parent then
if not hit then return end
if not CanDamage.Value then return end
local enemyHumanoid = hit.Parent:FindFirstChild("Humanoid")
if enemyHumanoid == IsHum or hit.Parent:FindFirstChild("NPCWaterKingdomVALUE") then return end
if enemyHumanoid then
enemyHumanoid:TakeDamage(100)
anim:Play()
SwingSound:Play()
SwordHit:Play()
script.Disabled = true
CanDamage.Value = false
wait(1)
anim:Stop()
CanDamage.Value = true
script.Disabled = false
enemyHumanoid.Died:Connect(function()
script.Parent.Parent.Chase.Disabled = true
script.Parent.Parent.NPCMovement.Disabled = false
script.Parent.Humanoid.WalkSpeed = 12
script.Disabled = false
script.Disabled = true
end)
end
end
end)
The Script I’m Stuck With
enemyHumanoid.Died:Connect(function()
script.Parent.Parent.Chase.Disabled = true
script.Parent.Parent.NPCMovement.Disabled = false
script.Parent.Humanoid.WalkSpeed = 12
script.Disabled = false
script.Disabled = true
end)