I’m using the code below to render the movement of an NPC along a path X, as if it were a tower defense on the client. However, every time a player gets close, the nearest NPC stops moving.
local minion = tycoonModel.MinionsInWorld[minionName]
if not minion then return end
local CurrencyPoint = replicator.Spawner.SpawnerExit.WorldCFrame.Position
local OldPoint
local WaysLIST = {}
local Path = 1
for i,waypoint in pairs(tycoonModel.MainItens.ConveyorBelt.Path:GetChildren()) do
WaysLIST[waypoint.Name] = waypoint.Position
end
local Animator = minion.Humanoid.Animator
local Animation = Instance.new("Animation")
Animation.Parent = Animator
Animation.AnimationId = "rbxassetid://14777263766"
local AnimationTrack = Animator:LoadAnimation(Animation)
task.wait()
AnimationTrack:Play()
minion.Humanoid:MoveTo(CurrencyPoint)
minion.Humanoid.MoveToFinished:Connect(function()
if CurrencyPoint == WaysLIST["Goal"] then
minion:Destroy()
end
CurrencyPoint = WaysLIST["WAY_POINT"..Path]
if not CurrencyPoint then
CurrencyPoint = WaysLIST["GOAL"]
end
minion.Humanoid:MoveTo(CurrencyPoint)
Path += 1
end)
Can someone tell me what to do to solve or fix this issue? The NPC simply stops, and when the player moves away, it starts moving normally again.