What happened here? (TweenModelService Script)

The model becomes unanchored and fall over on one of the waypoints
the forum:
https://devforum.roblox.com/t/tweenmodelservice-easily-tween-models/1883874

the video of the model falling down:
https://media.discordapp.net/attachments/920102333092872202/1101778425955487854/RobloxStudioBeta_J3mZkIuIAX.gif
the script:

function WaypointTween() -- lazy to space out lines
	local pointinfo = TweenInfo.new(1,Enum.EasingStyle.Linear)
	local pointendinfo = TweenInfo.new(5,Enum.EasingStyle.Quad,Enum.EasingDirection.Out)
	local pointstartinfo = TweenInfo.new(5,Enum.EasingStyle.Quad,Enum.EasingDirection.In)
	
	local point1goal = {} -- goal 1
	point1goal.CFrame = pos1.CFrame
	TweenModelService:Create(ParttoTween, pointstartinfo, point1goal):Play()
	task.wait(5)
	local point2goal = {} -- goal 2
	point2goal.CFrame = pos2.CFrame
	TweenModelService:Create(ParttoTween, pointinfo, point2goal):Play()
	task.wait(3)
	local point3goal = {} -- goal 3
	point3goal.CFrame = pos3.CFrame
	TweenModelService:Create(ParttoTween, pointinfo, point3goal):Play()
	task.wait(3)
	local point4goal = {} -- goal 4
	point4goal.CFrame = pos4.CFrame
	TweenModelService:Create(ParttoTween, pointinfo, point4goal):Play()
	task.wait(3)
	local point5goal = {} -- goal 5
	point5goal.CFrame = pos5.CFrame
	TweenModelService:Create(ParttoTween, pointinfo, point5goal):Play()
	task.wait(3)
	local point6goal = {} -- goal 6
	point6goal.CFrame = pos6.CFrame
	TweenModelService:Create(ParttoTween, pointinfo, point6goal):Play()
	task.wait(3)
	local point7goal = {} -- goal 7
	point7goal.CFrame = pos7.CFrame
	TweenModelService:Create(ParttoTween, pointinfo, point7goal):Play()
	task.wait(3)
	local pointlastgoal = {} -- Last Goal
	pointlastgoal.CFrame = ToPart.CFrame
	TweenModelService:Create(ParttoTween, pointendinfo, pointlastgoal):Play()
end

the tweenmodelservice script:

local TweenService = game:GetService("TweenService")

local TweenModelService = {}

function TweenModelService:Create(Model: Model, TweenInfo: TweenInfo, TeleportTo: any)
	if not Model.PrimaryPart then
		warn("Model must have a PrimaryPart in order to be tweened properly. The tween returned as nil.")
		return nil
	end
	
	local WeldTable = {}
	local PartAnchoredState = {}
	
	for _, Part in Model:GetDescendants() do
		if Part:IsA("BasePart") then
			local WeldConstraint = Instance.new("WeldConstraint")
			WeldConstraint.Enabled = false
			WeldConstraint.Part0 = Part
			WeldConstraint.Part1 = Model.PrimaryPart
			WeldConstraint.Parent = Part
			table.insert(WeldTable, WeldConstraint)
			PartAnchoredState[Part] = Part.Anchored
		end
	end
	
	local Tween = TweenService:Create(Model.PrimaryPart, TweenInfo, TeleportTo)		
	
	local ModelTween = {}
	
	local function RevertStateOfModel(Message)
		for _, WeldConstraint in WeldTable do
			WeldConstraint.Enabled = false
			if Message == "DestroyWelds" then
				WeldConstraint:Destroy()
			end
		end
		for _, PartsInModel in Model:GetDescendants() do
			if PartsInModel:IsA("BasePart") then
				PartsInModel.Anchored = PartAnchoredState[PartsInModel]
			end
		end
	end
	
	function ModelTween:Play()
		for _, WeldConstraint in WeldTable do
			WeldConstraint.Enabled = true
		end
		for _, PartsInModel in Model:GetDescendants() do
			if PartsInModel:IsA("BasePart") then
				PartsInModel.Anchored = false
			end
		end
		Tween.Completed:Once(function()
			RevertStateOfModel()
		end)
		Model.PrimaryPart.Anchored = true
		Tween:Play()
	end
	
	function ModelTween:Pause()
		Tween:Pause()
	end
		
	function ModelTween:Cancel()
		Tween:Cancel()
		RevertStateOfModel()
	end
	
	function ModelTween:Destroy()
		Tween:Destroy()
		RevertStateOfModel("DestroyWelds")
	end
	
	ModelTween.TweenInfo = Tween.TweenInfo
	ModelTween.Instance = Model
	
	ModelTween.Welds = WeldTable
	ModelTween.PlaybackState = Tween.PlaybackState
	Tween:GetPropertyChangedSignal("PlaybackState"):Connect(function()
		ModelTween.PlaybackState = Tween.PlaybackState
	end)
	
	ModelTween.Completed = Tween.Completed
	
	return ModelTween
end

return TweenModelService
1 Like

Hmm… It seems looks like its not anchored.

Try to anchor it!

3 Likes

I already anchor all of it, the cause is from the TweenModelService script on its own. I can’t find a way to stop it from unanchoring/destroying the welds

1 Like

The problem is that welds break when positioned.
You need to tweenservice the primarypart and unanchor everything that its welded

2 Likes

It is very normal, if you are using weld. If you want to move welded, you need to make PrimaryPart and weld parts to PrimaryPart. Then move PrimaryPart to wherever you want.

1 Like

Are you getting any errors in the output? When I made TweenModelService, it always reanchored everything that was anchored. It temporarily welded all of the models then unanchored it, and when the tween was done, it anchored everything that was anchored, then unwelded it.

nope, it doesn’t made any errors

1 Like