Hey, I’m trying to make a model follow a player using PathfindingService to create ‘paths’ and then tweening it between those paths. The model isn’t moving at all, but the print right after they tween is working. I don’t get any errors from the script and the parts marking the waypoint show up correctly.
Ignore the if DistanceTravelled, I’m going to change that later.
local tweenService = game:GetService("TweenService")
local tweeningInformation = TweenInfo.new(
0.1, -- length
Enum.EasingStyle.Linear, -- Easing style of the tweeninfo
Enum.EasingDirection.In, --Easing direction of the tweeninfo
1, -- number of times the tween will repeat
false, --should the tween repeat?
2 --- delay between each tween
)
local PathfindingService = game:GetService("PathfindingService")
-- Define the Pet and player
local Pet = script.Parent
local humanoid = Pet.PrimaryPart
-- Variables to store waypoints table and pet's current waypoint
local waypoints
local currentWaypointIndex
local function followPath(destinationObject, path)
-- Compute and check the path
path:ComputeAsync(Pet.PrimaryPart.Position, destinationObject.Position)
-- Empty waypoints table after each new path coputation
waypoints = {}
if path.Status == Enum.PathStatus.Success then
-- Get the path waypoints and start pet walking
waypoints = path:GetWaypoints()
for _, waypoint in pairs(waypoints) do
local part = Instance.new("Part")
part.Shape = "Ball"
part.Material = "Neon"
part.Size = Vector3.new(1,1,1)
part.Position = waypoint.Position
part.Anchored = true
part.CanCollide = false
part.Parent = game.Workspace
end
for _, waypoint in pairs(waypoints) do
local propertyTable = {
Position = waypoint.Position
}
local tween = tweenService:Create(Pet.PrimaryPart, tweeningInformation, propertyTable)
tween:Play()
print("playing")
end
end
end
while true do
local destination = script.Parent.Parent:WaitForChild("HumanoidRootPart")--define the destination
local Character = script.Parent.Parent
local HRP = Character:WaitForChild('HumanoidRootPart')
local CurrentPosition = HRP.Position
local DistanceTravelled = (CurrentPosition - HRP.Position).Magnitude
if DistanceTravelled <= 10 then
local path = PathfindingService:CreatePath()--Create a path
followPath(destination, path)
else
print("teleporting to the character")
Character:FindFirstChild(Character.Name.."'s Pet"):SetPrimaryPartCFrame(Character.HumanoidRootPart.CFrame)
end
wait(1)
end
Thank you!