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

i am having trouble with making a monster go to a player ( using pathfinding )?

Asked by 2 years ago
Edited 2 years ago

the scipt:

local PathfindingService = game:GetService("PathfindingService")

local humaniod = script.Parent:WaitForChild("Humanoid") local body = script.Parent:WaitForChild("HumaniodRootPart") or script.Parent:WaitForChild("Torso")

local PlayerLocked

game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(char) local function NearestPlayer()

            local distance = 1000000000000000000000
            local PlayerLocked2

            for i, Player in pairs(player.Character) do
                if Player.Character then

                    local distance2 = (Player.Character.HumaniodRootPart.Position - script.Parent.HumaniodRootPart.Position).Magnitude

                    if distance2 < distance then

                        distance = distance2
                        PlayerLocked2 = Player.Position
                        PlayerLocked = PlayerLocked2

                    end

                end
            end

            local path = PathfindingService:CreatePath()

        wait(0.5)

            path:ComputeAsync(body.Position, PlayerLocked)

            local waypoints = path:GetWaypoints()

                    for k, waypoint in pairs(waypoints) do
                    humaniod:MoveTo(waypoint.Position)

                        if waypoint.Action == Enum.PathWaypointAction.Jump then
                        humaniod:ChangeState(Enum.HumanoidStateType.Jumping)
                        end

                    humaniod.MoveToFinished:Wait()
                    end

            end         
    end)

end)

0
its a a little weird some of the code is not converted so read from the top Deadx_scripts -2 — 2y

Answer this question