Why is this not working?
Please make your question title relevant to your question content. It should be a one-sentence summary in question form.
01 | local Self = script.Parent; |
02 | local Humanoid = Self:WaitForChild( "Humanoid" ); |
03 | local Torso = Self:WaitForChild( "Torso" ); |
04 | local Pathfinding = game:GetService( "PathfindingService" ); |
05 | local findplayer = script.Parent.playername.Value |
06 | local Player = game.Players:WaitForChild(findplayer) |
08 | local MinimumDistance = 500 |
10 | function FetchCoordinate() |
12 | Position = Torso.Position; |
13 | Distance = MinimumDistance; |
15 | local pCharacter = Player.Character; |
16 | local pTorso = pCharacter:FindFirstChild( "Torso" ); |
17 | if (pCharacter and pTorso and Player:DistanceFromCharacter(Torso.Position) < Target.Distance) then |
18 | Target.Position = pTorso.Position; |
19 | Target.Distance = Player:DistanceFromCharacter(Torso.Position) < Target.Distance; |
21 | local Coordinates = Pathfinding:ComputeSmoothPathAsync(Torso.Position, Target.Position, MinimumDistance):GetPointCoordinates(); |
22 | return Coordinates [ math.min(#Coordinates, 2 ) ] ; |
26 | Humanoid:MoveTo(FetchCoordinate()) |
27 | Humanoid.MoveToFinished:wait() |
this is a pathfind script. this will follow the player whos name is in findplayer. this script will not work the error in the output is. 00:13:40.929 - Workspace.Player.Humanoid.Player's Cop.Main Script:15: attempt to index upvalue 'Player' (a nil value)
00:13:40.930 - Stack Begin
00:13:40.930 - Script 'Workspace.Player.Humanoid.Player's Cop.Main Script', Line 15 - global FetchCoordinate
00:13:40.930 - Script 'Workspace.Player.Humanoid.Player's Cop.Main Script', Line 26
00:13:40.931 - Stack End