Hi! I am trying to make my zombie in my game go after players all the time. Also goes after the same player if in range.
I have tried to fix this but I am still at a loss.
I have looked already but no solutions answer my problem currently.
[quote=“greeninja_97, post:1, topic:1837847, full:true”]
Hi! I am trying to make my zombie in my game go after players all the time. Also goes after the same player if in range.
I have tried to fix this but I am still at a loss.
I have looked already but no solutions answer my problem currently.
SCRIPT:
wait()
local hum = script.Parent:FindFirstChild("Humanoid")
local torso = script.Parent:FindFirstChild("HumanoidRootPart")
local max_dist = 200
function findNearestTorso()
for _, player in pairs(game.Players:GetPlayers()) do
if player.Character ~= nil then
local target_torso = player.Character:FindFirstChild("HumanoidRootPart")
if target_torso ~= nil then
if (target_torso.Position - torso.Position).magnitude < max_dist then
return target_torso
end
end
end
end
end
local old_pos = torso.Position
wait(math.random(0, 90)/100)
while hum ~= nil do
local target = findNearestTorso()
if target ~= nil then
while target ~= nil and target.Parent ~= nil and hum ~= nil do
if (target.Position - torso.Position).magnitude < max_dist then
hum:MoveTo(target.Position, target)
if target.Position.Y > torso.Position.Y + 3 then
hum.Jump = true
end
if (old_pos - torso.Position).magnitude < 0.5 then
if math.random(1, 3) == 1 then
torso.Velocity = torso.CFrame.lookVector * -40
hum:MoveTo(torso.Position + Vector3.new(math.random(-1, 1), 0, math.random(-1, 1))*20)
wait(1.2)
else
--hum.Jump = true
hum:MoveTo(target.Position, target)
end
end
else break end
old_pos = torso.Position
wait(0.5)
end
end
wait(4)
end
If you can help me please do! Thanks!