I'm making a RPG game and I don't know how to make an enemy NPC that follow and kill players. If have anyone know that, please help me. I have try to run this script in Roblox Studio but it not do anything. This is my script code I don't know how to fix it:
players = nil; --Where we are going to store all the players
dummy = game.Workspace.Dummy; --Dummy reference
currentPlayerFollowing = nil; --The current player the zombie is following
damage = 2; --Change this for more damage if you want
function touched(hit)
--pcall allows for errors to be disregarded so you don't have to worry about random output errors
if pcall(function() if hit.Parent.Humanoid ~= nil then end end) then --If the character's health storage is there
pcall(function() hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - damage end); --Do damage
end
end
dummy.Torso.Touched:connect(touched);
while wait(1) do --Forever loop
players = game.Players:GetChildren(); --Grab all the Players currently in the game
for i = 0, table.getn(players), 1 do --Go through all of the players
if (players[i] ~= nil and (players[i].Character.Torso.Position - dummy.Torso.Position.X).magnitude <= 10) then --Subtract the distance between the player and the zombie
currentPlayerFollowing = players[i]; --Add the player to the currentPlayerFollowing reference so the zombie can follow them
end
end
if (currentPlayerFollowing ~= nil) then --If the player is there
dummy.Humanoid.WalkToPoint = currentPlayerFollowing.Character.Torso.Position --Walk to the player
end
end?
What happend with this? Please help me! Thank for your help.

1 comment
You don’t know how to fix it cause it’s not yours.