Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I am trying to add a stun to the enemy NPC and the localscript does not run at all. Why?

Asked by
Kami_Yo 72
5 years ago

Here is the LocalScript within the Orc enemy. It is meant to make it so the enemy gets stunned when they're hit. I commented out the wait() until since I thought that was what was causing the problem. But even the print statements won't run. Is this simply not possible for NPCs?

    Humanoid = script.Parent:WaitForChild("Enemy")

-- stun animation

local Stun = Instance.new("Animation")

Stun.AnimationId= "rbxassetid://02986478822"



local canAttack = script.Parent.CanAttack



--repeat wait() until Humanoid:IsDescendantOf(game.workspace:FindFirstChild("Enemies"))

print("Made it here")

print("Made it here")

print("Made it here")



local AnimationTrack = Humanoid:LoadAnimation(Stun)

AnimationTrack.Priority = Enum.AnimationPriority.Action



local LastKnownHealth

game:GetService('RunService').RenderStepped:Connect(function()

print("RENDERSTEPPED ORC")

if LastKnownHealth then

if LastKnownHealth > Humanoid.Health then

print('Playing')

canAttack.Value = false

AnimationTrack:Play()

end

end

LastKnownHealth = Humanoid.Health

end)
0
Local scripts are only meant for players. NPCs are not players, so this script won’t really work. Change it to a server (normal) script and replace the RenderStepped loop with a while true do loop (with a wait()) or the HealthChanged event on the humanoid. User#20279 0 — 5y

Answer this question