Ok so im making a model’s primary part (humanoidRootPart) lerp and for some reason the model’s parts are not following the humanoid root part. Iv’e tried changing the model and it gave me the same results. The model needs to be anchored and it has no humanoid whatsoever in it. Any solutions?
Here’s my code that lerps the humanoid root part:
function Move_Enemy(enemy, enemyID)
for x, node in pairs(workspace.Path.Nodes:GetChildren()) do
local runTime = 0
local alpha = 0
local moveLerp
local nextNode = workspace.Path.Nodes:FindFirstChild(tostring(x + 1))
local previousNode = workspace.Path.Nodes:FindFirstChild(tostring(x - 1))
if not previousNode then previousNode = workspace.Path.StartNode end
local startCFrame = workspace.Enemies[tostring(enemyID)].HumanoidRootPart.CFrame
local pathOffset = workspace.Enemies[enemyID]:GetAttribute("PathOffset")
local nodeAttribute = workspace.Enemies[enemyID]:GetAttribute("Node")
local pathZOffset = nil
if node:GetAttribute("Direction") == "Left" then pathZOffset = -pathOffset else pathZOffset = pathOffset end
if not nextNode then pathZOffset = 0 end
local distance = (node.Position - previousNode.Position).Magnitude
local lerpTime = distance / enemy.Speed
local nodeOffsetCFrame = node.CFrame * CFrame.new(pathOffset, 0, pathZOffset)
moveLerp = RunService.Heartbeat:Connect(function(deltaTime)
task.wait()
runTime += deltaTime
alpha = runTime / lerpTime
workspace.Enemies[tostring(enemyID)].HumanoidRootPart.CFrame = startCFrame:Lerp(nodeOffsetCFrame, alpha)
if alpha >= 1 then moveLerp:Disconnect() end
end)
repeat task.wait() until alpha >= 1
if nextNode then
workspace.Enemies[enemyID].HumanoidRootPart.CFrame = CFrame.lookAt(workspace.Enemies[enemyID].HumanoidRootPart.Position, nextNode.Position)
else
workspace.Enemies[enemyID]:Destroy()
end
end
end
Are all the model’s parts welded to the HumanoidRootPart?
Also, try using :PivotTo.
Code:
function Move_Enemy(enemy, enemyID)
for x, node in pairs(workspace.Path.Nodes:GetChildren()) do
local runTime = 0
local alpha = 0
local moveLerp
local nextNode = workspace.Path.Nodes:FindFirstChild(tostring(x + 1))
local previousNode = workspace.Path.Nodes:FindFirstChild(tostring(x - 1))
if not previousNode then previousNode = workspace.Path.StartNode end
local startCFrame = workspace.Enemies[tostring(enemyID)].HumanoidRootPart.CFrame
local pathOffset = workspace.Enemies[enemyID]:GetAttribute("PathOffset")
local nodeAttribute = workspace.Enemies[enemyID]:GetAttribute("Node")
local pathZOffset = nil
if node:GetAttribute("Direction") == "Left" then pathZOffset = -pathOffset else pathZOffset = pathOffset end
if not nextNode then pathZOffset = 0 end
local distance = (node.Position - previousNode.Position).Magnitude
local lerpTime = distance / enemy.Speed
local nodeOffsetCFrame = node.CFrame * CFrame.new(pathOffset, 0, pathZOffset)
moveLerp = RunService.Heartbeat:Connect(function(deltaTime)
task.wait()
runTime += deltaTime
alpha = runTime / lerpTime
workspace.Enemies[tostring(enemyID)]:PivotTo(startCFrame:Lerp(nodeOffsetCFrame, alpha))
if alpha >= 1 then moveLerp:Disconnect() end
end)
repeat task.wait() until alpha >= 1
if nextNode then
workspace.Enemies[enemyID].HumanoidRootPart.CFrame = CFrame.lookAt(workspace.Enemies[enemyID].HumanoidRootPart.Position, nextNode.Position)
else
workspace.Enemies[enemyID]:Destroy()
end
end
end