Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is this not working?

Asked by
Benqazx 108
8 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.
local Self=script.Parent;
local Humanoid=Self:WaitForChild("Humanoid");
local Torso=Self:WaitForChild("Torso");
local Pathfinding=game:GetService("PathfindingService");
local findplayer = script.Parent.playername.Value
local Player = game.Players:WaitForChild(findplayer)

local MinimumDistance = 500

function FetchCoordinate()
    local Target={
        Position=Torso.Position;
        Distance=MinimumDistance;
    }
        local pCharacter=Player.Character;
        local pTorso=pCharacter:FindFirstChild("Torso");
        if(pCharacter and pTorso and Player:DistanceFromCharacter(Torso.Position) < Target.Distance)then
            Target.Position=pTorso.Position;
            Target.Distance=Player:DistanceFromCharacter(Torso.Position) < Target.Distance;
    end
    local Coordinates=Pathfinding:ComputeSmoothPathAsync(Torso.Position, Target.Position, MinimumDistance):GetPointCoordinates();
    return Coordinates[math.min(#Coordinates, 2)];
end

while true do
    Humanoid:MoveTo(FetchCoordinate())
    Humanoid.MoveToFinished:wait()
end

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

1 answer

Log in to vote
2
Answered by 8 years ago
local Self = script.Parent;
local Humanoid = Self:WaitForChild("Humanoid");
local Torso=Self:WaitForChild("Torso");
local Pathfinding = game:GetService("PathfindingService");
local findplayer = script.Parent.playername.Value
local Player = game.Players:WaitForChild(findplayer)

local MinimumDistance = 500

function FetchCoordinate()
    local Target={
        Position = Torso.Position;
        Distance = MinimumDistance;
    }
        local pCharacter = Player.Character;
        local pTorso = pCharacter:FindFirstChild("Torso");
        if(pCharacter and pTorso and Player:DistanceFromCharacter(Torso.Position) < Target.Distance)then
            Target.Position=pTorso.Position;
            Target.Distance=Player:DistanceFromCharacter(Torso.Position) < Target.Distance;
    end
    local Coordinates = Pathfinding:ComputeSmoothPathAsync(Torso.Position, Target.Position, MinimumDistance):GetPointCoordinates();
    return Coordinates[math.min(#Coordinates, 2)];
end

while true do
    Humanoid:MoveTo(FetchCoordinate())
    Humanoid.MoveToFinished:wait()
end


Should work now!

0
can you put that in the lua script thing please because its hard to understand it like this Benqazx 108 — 8y
0
ty for the help it works now Benqazx 108 — 8y
0
Np TheUniPiggy 77 — 8y
Ad

Answer this question