I've been stuck on my script for a while 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.

How would I fix this?

My Entire Script: (Sorry if the script looks weirdly organised. This is just how I like the look of my scripts)

 --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 trying to work with:

enemyHumanoid.Died:Connect(function()
script.Parent.Parent.Chase.Disabled = true
script.Parent.Parent.NPCMovement.Disabled = false
script.Parent.Humanoid.WalkSpeed = 12
script.Disabled = true
end)

2 comments

0

Try using indentation. I don't know if its the formatting, but it creates problems with if statements and functions if you dont indent properly. Does this work? :)

0

Doesn't work unfortunately