- What do you want to achieve? Keep it simple and clear!
I have zombies for my game that I hope reaches front page. I have 1 main script that controls all the zombies(2 zombies) and I want them to move smoothly
- What is the issue? Include screenshots / videos if possible!
The issue is that sometimes the zombies teleport when they get close. Ik its pretty confusing but if they’re like 2 studs away from u they just suddenly become next to u.
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried to reread the code but the only solution that’s reasonable for me is just lag. I have tried to do it in hidden developers but this dude just said I wasn’t putting in effort and that I should reread my code and that the code does what I tell it to do which is true but it wasn’t helpful at all. I honestly wouldn’t be surprised if it’s lag because I just could not see a single issue.
local tagged = game:GetService("CollectionService")
local distance = 50
local FindNearestChar = function(hrp)
local target = 50
local kill = nil
for i, v in pairs(game.Players:GetPlayers()) do
if v.Character then
if v.Character:FindFirstChild("HumanoidRootPart") then
if (v.Character.HumanoidRootPart.CFrame.Position - hrp.CFrame.Position).Magnitude <= distance and (v.Character.HumanoidRootPart.CFrame.Position - hrp.CFrame.Position).Magnitude <= target then
target = (v.Character.HumanoidRootPart.CFrame.Position - hrp.CFrame.Position).Magnitude
kill = v.Character
end
end
end
end
return kill
end
for i, npcs in pairs(tagged:GetTagged("Hostile")) do
local klone = npcs:Clone()
tagged:RemoveTag(klone, "Hostile")
local walktrack = npcs.Humanoid:LoadAnimation(script.Walk)
coroutine.wrap(function()
while true do
wait(.1)
local char = FindNearestChar(npcs.HumanoidRootPart)
if char and npcs.Humanoid.Health > 0 then
npcs.Humanoid:MoveTo(char.PrimaryPart.CFrame.Position)
if not walktrack.IsPlaying then
walktrack:Play()
end
else
npcs.Humanoid:MoveTo(npcs.HumanoidRootPart.Position)
walktrack:Stop()
end
end
end)()
local function oof()
npcs.Humanoid.Died:Connect(function()
for lo, thing in pairs(npcs:GetChildren()) do
thing:Destroy()
end
for lol, v in pairs(klone:GetChildren()) do
v.Parent = npcs
end
npcs.PrimaryPart = npcs:WaitForChild("HumanoidRootPart")
klone:Destroy()
klone = npcs:Clone()
walktrack = npcs.Humanoid:LoadAnimation(script.Walk)
oof()
end)
end
oof()
end
no errors, occasionally the zombies stop and teleport and I’ll just blame it on lag