Hello guys again! I come to you with a new issue.
In the game I am making, I have a script that makes the NPC follow the player, but..
If the player gets hit by the enemy mob and dies, the enemy mob continues following the player when the player respawns as it is expected to do. However..since there are gaps players are to jump over, if the player falls into the void; the enemy NPC wont follow the player after the player respawns.
local aihumroot = script.Parent.HumanoidRootPart
local aihum = script.Parent.Humanoid
while true do
for _,plr in pairs(game.Players:GetPlayers()) do
if plr.Character then
local char = plr.Character
if (char.HumanoidRootPart.Position-aihumroot.Position).magnitude <= 30 then
aihum:MoveTo(char.HumanoidRootPart.Position)
end
end
end
wait()
end
This is the current code I have.
(credit to Eagle022 for helping me simplify and understand where I went wrong in my original code btw)

5 comments
does the code error when you jump into the void?
where can i find the syntax errors on studio? i had no idea they existed on roblox studio
here it is; 17:33:29.706 - HumanoidRootPart is not a valid member of Model 17:33:29.706 - Stack Begin 17:33:29.708 - Script 'Workspace.Drooling Zombie.Script', Line 8 17:33:29.709 - Stack End 17:33:29.724 - HumanoidRootPart is not a valid member of Model
That just means that you don't have "HumanoidRootPart" defined in the CharacterModel of the NPC.
When a player's Humanoid dies, their character is (usually) reset. You have to add an if statement to check if the HumanoidRootPart exists before checking the magnitude of its relative position to the AI's position.