I’m trying to make an attack animation play when a player gets within a zombie npc, but I don’t know how to always check if the player is within the range and play the animation without it playing a thousand times.
Not full code but the stuff that’s important
local plr = game.Players:GetPlayerFromCharacter(Goal.Parent)
RS.Stepped:Connect(function()
if (NPC.HumanoidRootPart.Position - Goal.Position).Magnitude <= 100 then
NPC.Humanoid:MoveTo(Goal.Position, Goal)
setNetworkOwner(NPC, plr)
if (NPC.HumanoidRootPart.Position - Goal.Position).Magnitude <= 7 then
animPlay("Attack")
end
else
setNetworkOwner(NPC, nil)
end
end)
function animPlay(anim)
if debounce == false then
debounce = true
anims[anim]:Play()
task.wait(.1)
end
debounce = false
end