So in this script, i made it so when a player is in range of the mob, it will try and hunt down the player. But when a player leaves they get glitched and will stay still. They still do damage though
local pathfind = game:GetService("PathfindingService")
local statsfolder = script.Parent:WaitForChild("STATSFOLDER")
local humanoid = script.Parent:WaitForChild("Humanoid")
local mindamage = statsfolder:WaitForChild("MinDamage")
local maxdamage = statsfolder:WaitForChild("MaxDamage")
local visiondistance = statsfolder:WaitForChild("VisionStud")
local targetvalue = statsfolder:WaitForChild("Target")
local position = statsfolder:WaitForChild("Position")
local torso = script.Parent:WaitForChild("Torso")
local enabled = false
math.randomseed(tick()-wait(1))
--Damaging Player
torso.Touched:connect(function(part)
if part.Parent:FindFirstChild("Humanoid") and part.Parent.Name ~= "NPC" and enabled == false then
enabled = true
local humanoid = part.Parent:WaitForChild("Humanoid")
humanoid:TakeDamage(math.random(mindamage.Value, maxdamage.Value))
wait(2)
enabled = false
else
enabled = true
humanoid.Jump = true
wait(1.5)
enabled = false
end
end)
function FindHumanoid()
local allplayers = game.Players:GetPlayers()
for i, v in pairs(allplayers) do
if v.Character and v.Character:FindFirstChild("Humanoid").Health > 0 then
local targettorso = v.Character:FindFirstChild("Torso")
local location = (torso.Position - targettorso.Position).magnitude
if location < visiondistance.Value then
targetvalue.Value = v.Character
else
end
end
end
end
--If player health is higher then 0 then they follow the player
while humanoid.Health > 0 do
FindHumanoid()
if targetvalue.Value then
local rtorso = targetvalue.Value:FindFirstChild("Torso")
if rtorso then
local path = pathfind:ComputeSmoothPathAsync(torso.Position, rtorso.Position, 200)
local check = path:GetPointCoordinates()
for i = 1, #check do
local singularpoints = check[i]
humanoid:MoveTo(singularpoints)
end
else
end
else
end
wait(0.5)
end

2 comments
Of course you will need to edit your code to use the returned value instead
Oh it works, thanks alot! :D