how would I fix these errors in a NPC follow script?
Asked by
4 years ago Edited 4 years ago
honestly Idk how many errors there are i got this online so please do a check for viruses as well thx! :)
01 | local NPC = script.Parent |
02 | local Humanoid = script.Parent:FindFirstChild( "Humanoid" ) |
03 | local HRP = script.Parent:FindFirstChild( "HumanoidRootPart" ) |
04 | local function GetClosestPlayer(range) |
07 | for i, v in pairs (game.Players:GetPlayers()) do |
08 | local dist = v:DistanceFromCharacter(HRP.position) |
10 | table.insert(List, { dist, v } ) |
14 | table.sort(List, function (A, B) |
25 | local NPC = script.Parent |
26 | local Humanoid = script.Parent:FindFirstChild( "Humanoid" ) |
27 | local HRP = script.Parent:FindFirstChild( "HumanoidRootPart" ) |
29 | local function GetClosestPlayer(range) |
32 | for i, v in pairs (game.Players:GetPlayers()) do |
33 | local dist = v:DistanceFromCharacter(HRP.position) |
35 | table.insert(List, { dist, v } ) |
39 | table.sort(List, function (A, B) |
52 | local Target = getClosestPlayer( 30 ) |
53 | if Target = = nil then return end |
54 | Humanoid:MoveTo(Target.PrimaryPart) |
55 | Humanoid.MoveToFinished:Wait() |
Ps: I dont have the errors I kinda left the game alone and never went back to it lol its somewhere XD