I am making a rpg game where the mobs chase you and after a while they stop, i got that working however i dont know how to make them walk back to their spawning location after they stopped chasing me, can someone please help me with this
this is the script that i use for following
local _M = require(script.Parent.MobConfig) local Mob = script.Parent local Enemy = Mob.Enemy function findNearestTorso(pos) local dist = _M.FollowDistance local torso,temp,human,temp2 = nil for _,v in pairs(game.Players:GetPlayers()) do if (not v.Character) then return end temp2 = v.Character temp = temp2:FindFirstChild("Torso") human = temp2:FindFirstChild("Humanoid") if (temp) and (human) and (human.Health > 0) then if (temp.Position - pos).magnitude < dist then if ((temp.Position - pos).magnitude < 1.50) then return end torso = temp dist = (temp.Position - pos).magnitude end end end return torso end while true do wait(_M.FollowDelay) local target = findNearestTorso(Mob.Torso.Position) if target ~= nil then Enemy:MoveTo(target.Position, target) end end
Closed as Not Constructive by Leamir
This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.
Why was this question closed?