im trying to tween a character but only the HRP is correctly moving, everything else moves but with an offset like it gets far from the HRP for some reason. note that everything is welded to the HRP and everything is unanchored other than the HRP so idk what is going wrong, this is the script
local HRP = script.Parent:WaitForChild('HumanoidRootPart')
local TS = game:GetService('TweenService')
local wayPoints = {HRP.Position, Vector3.new(-5838.778, 144.517, 245.852), Vector3.new(-5864.779, 146.685, 250.74)}
local Speed = 16
local TurnTime = 3
function GetTime(Point1, Point2)
local Distance = (Point1 - Point2).Magnitude
local Time = Distance / Speed
return Time
end
local function redo()
task.wait()
for _,wayPoint in pairs(wayPoints) do
if wayPoint == HRP.Position then continue end
TS:Create(
HRP,
TweenInfo.new(TurnTime),
{['CFrame'] = CFrame.lookAt(HRP.Position, wayPoint)}
):Play()
task.wait(TurnTime)
local Time = GetTime(HRP.Position, wayPoint)
TS:Create(
HRP,
TweenInfo.new(Time),
{['Position'] = wayPoint}
):Play()
task.wait(Time)
end
redo()
end
redo()
Make sure to replace script.Parent in the first line with the appropriate way to get the character reference.
local character = script.Parent -- Replace with the appropriate way to get the character reference
local humanoidRootPart = character:WaitForChild('HumanoidRootPart')
local tweenService = game:GetService('TweenService')
local wayPoints = {
humanoidRootPart.Position,
Vector3.new(-5838.778, 144.517, 245.852),
Vector3.new(-5864.779, 146.685, 250.74)
}
local Speed = 16
local TurnTime = 3
function GetTime(point1, point2)
local distance = (point1 - point2).Magnitude
local time = distance / Speed
return time
end
local function MoveCharacter()
while true do
for _, wayPoint in ipairs(wayPoints) do
if wayPoint == humanoidRootPart.Position then
continue
end
local lookAtCFrame = CFrame.lookAt(humanoidRootPart.Position, wayPoint)
local tweenInfo = TweenInfo.new(TurnTime)
for _, part in ipairs(character:GetDescendants()) do
if part:IsA("BasePart") then
tweenService:Create(
part,
tweenInfo,
{ ['CFrame'] = lookAtCFrame }
):Play()
end
end
task.wait(TurnTime)
local time = GetTime(humanoidRootPart.Position, wayPoint)
for _, part in ipairs(character:GetDescendants()) do
if part:IsA("BasePart") then
tweenService:Create(
part,
TweenInfo.new(time),
{ ['Position'] = wayPoint }
):Play()
end
end
task.wait(time)
end
end
end
MoveCharacter()