I have this script in my “Zombie” model in ServerStorage, I have a script where it follows the nearest player but i want a bit more advanced one, for some reason there isnt any good videos/help on youtube and other platforms,
Can someone send me their best script where the zombie follows the nearest player and if there is a wall or something it tries another way, and if it touches a player the players damage becomes less and less
Please come up or copy and paste a good script for me, thanks a lot
Don’t expect people to write entire systems for you.
I’m not going to write a script but this tutorial should help with pathfinding:
Then to make the zombie damage the player you just use a Touched event with a debounce to deal a set amount of damage.
That would look something like this:
local Debounce = {}
script.Parent.HumanoidRootPart.Touched:Connect(function(hit)
local hum = hit.Parent:FindFirstChild("Humanoid")
if hum and not table.find(hit.Parent.Name) then
table.insert(Debounce,hit.Parent.Name)
hum:TakeDamage(10)
task.wait(1)
table.remove(table.find(hit.Parent.Name))
end
end)
I think this is the hardest bit that many people struggle with, what I recommend is trying to use raycasts to detect the wall or some sort of pathfinding at certain intervals. It’s hard though. I struggled to do it for many months and still couldn’t make it 100% properly. So good luck.
I have come across this issue before when I was making an advanced zombie to hunt players down. I think that like @Awwsoomee mentioned, roblox’s Pathfinding Service is the best way of getting around this. Pathfinding service essentially, well as its name suggests, finds a path from point A to point B, something like roblox’s click to move in games (correct me if i’m wrong about it being like click to move). What I did for my zombies was to use a loop through all the players to locate the nearest player, then use path finding service to find the path for the zombie to take, make the zombie walk that way, then wrap the entire thing in a good ol’ while true do loop.