Doge falling apart

You can write your topic however you want, but you need to answer these questions:
I’m trying to make a dog that goes to a button and presses it when you feed it.

The dog falls apart after about two times of feeding it.
image

I’m using a modulescript to tween the dogs motion.

Modulescript:

local module = {}
module.__index = module

local TS = game:GetService("TweenService")
local Debris = game:GetService("Debris")

local function CalculatePosition(part1,part2)
	return CFrame.new(part1.Position):ToObjectSpace(CFrame.new(part2.Position)).Position
end

function module.TweenModulePosition(Model,Tweeninfo,PPosition)
	if typeof(Model) ~= "Instance" then error(Model.." isnt a instance") end
	if not Model:IsA("Model") then error(Model.Name.." isnt a model") end
	if not Model.PrimaryPart then Model.PrimaryPart = Model:FindFirstChildWhichIsA("BasePart") end


	task.spawn(function()
		local Primary = Model.PrimaryPart
		local AnchorState = Primary.Anchored

		local TW = TS:Create(Primary,Tweeninfo,{Position = PPosition})
		
		for _,v in pairs(Model:GetDescendants()) do
			if v:IsA("BasePart") and v ~= Primary then
				local T = TS:Create(v,Tweeninfo,{Position = PPosition + CalculatePosition(Primary,v)})
				T:Play()
				
				local anchord = v.Anchored
				v.Anchored = true 
				task.spawn(function()
					TW.Completed:Wait()
					v.Anchored = anchord
				end)
			end

			if v:IsA("Weld") or v:IsA("WeldConstraint") or v:IsA("ManualWeld") or v:IsA("Motor6D") then
				if v.Name ~= "TweenWeld" then
					v.Enabled = false
					task.spawn(function()
						TW.Completed:Wait()

						v.Enabled = true
					end)
				end
			end
		end

		TW:Play()
		TW.Completed:Wait()
		
		Primary.Anchored = AnchorState
	end)
	return
end

function module.TweenModuleScale(Model,Tweeninfo,Size)
	if typeof(Model) ~= "Instance" then error(Model.." isnt a instance") end
	if not Model:IsA("Model") then error(Model.Name.." isnt a model") end
	if not Model.PrimaryPart then Model.PrimaryPart = Model:FindFirstChildWhichIsA("BasePart") end

	task.spawn(function()
		local Primary = Model.PrimaryPart
		local AnchorState = Primary.Anchored

		local TW = TS:Create(Primary,Tweeninfo,{Size = Primary.Size * Size})

		for _,v in pairs(Model:GetDescendants()) do
			if v:IsA("BasePart") and v ~= Primary then
				local state = v.Anchored
				v.Anchored = true
				local T = TS:Create(v,Tweeninfo,{Size = v.Size * Size;Position = v.Position + (CalculatePosition(Primary,v) * (Size-1))})
				
				task.spawn(function()
					TW:GetPropertyChangedSignal("PlaybackState"):Wait()
					if v:FindFirstChildWhichIsA("SpecialMesh") then
						local mesh = v:FindFirstChildWhichIsA("SpecialMesh")
						TS:Create(mesh,Tweeninfo,{Scale = mesh.Scale * Size}):Play()
					end
					T:Play()
					v.Anchored = state
				end)
			end

			if v:IsA("Weld") or v:IsA("WeldConstraint") or v:IsA("ManualWeld") or v:IsA("Motor6D") then
				if v.Name ~= "TweenWeld" then
					v.Enabled = false
					task.spawn(function()
						TW.Completed:Wait()
						v.Enabled = true
					end)
				end
			end
		end

		TW:Play()
		TW.Completed:Wait()

		Primary.Anchored = AnchorState
	end)

	return
end

function module.TweenModuleOrientation(Model,Tweeninfo,oOrinetation)
	if typeof(Model) ~= "Instance" then error(Model.." isnt a instance") end
	if not Model:IsA("Model") then error(Model.Name.." isnt a model") end
	if not Model.PrimaryPart then Model.PrimaryPart = Model:FindFirstChildWhichIsA("BasePart") end

	task.spawn(function()
		local Primary = Model.PrimaryPart
		local AnchorState = Primary.Anchored

		local TW = TS:Create(Primary,Tweeninfo,{CFrame = Primary.CFrame * CFrame.Angles(math.rad(oOrinetation.X),math.rad(oOrinetation.Y),math.rad(oOrinetation.Z))})

		for _,v in pairs(Model:GetDescendants()) do
			if v:IsA("BasePart") and v ~= Primary then
				local weld
				if not v:FindFirstChild("TweenWeld") then
					weld = Instance.new("WeldConstraint")
					weld.Part0 = Primary
					weld.Part1 = v
					weld.Parent = v
					weld.Name = "TweenWeld"
				else
					weld = v:FindFirstChild("TweenWeld")
					weld.Enabled = true
				end

				local anchord = v.Anchored
				v.Anchored = false
				task.spawn(function()
					TW.Completed:Wait()

					weld.Enabled = false
					v.Anchored = anchord
				end)
				
				continue
			end
			if v:IsA("Weld") or v:IsA("WeldConstraint") or v:IsA("ManualWeld") or v:IsA("Motor6D") then
				if v.Name ~= "TweenWeld" then
					v.Enabled = false
					task.spawn(function()
						TW.Completed:Wait()

						v.Enabled = true
					end)
				end
				
				continue
			end
			
			task.wait()
		end

		TW:Play()
		TW.Completed:Wait()

		Primary.Anchored = AnchorState
	end)
	return
end

function module.TweenModuleTransparency(Model,Tweeninfo,Transparency)
	if typeof(Model) ~= "Instance" then error(Model.." isnt a instance") end
	if not Model:IsA("Model") then error(Model.Name.." isnt a model") end
	for _,v in ipairs(Model:GetDescendants()) do
		if v:IsA("BasePart") then
			TS:Create(v,Tweeninfo,{Transparency = Transparency}):Play()
		end
	end
end

function module.TweenModuleColor(Model,Tweeninfo,ColorR)
	if typeof(Model) ~= "Instance" then error(Model.." isnt a instance") end
	if not Model:IsA("Model") then error(Model.Name.." isnt a model") end
	for _,v in ipairs(Model:GetDescendants()) do
		if v:IsA("BasePart") then
			TS:Create(v,Tweeninfo,{Color = ColorR}):Play()
		end
	end
end

return module

Script:

local TweenService = game:GetService("TweenService")
local food = script.Parent.Parent.Parent.Food
local proxPrompt = script.Parent
local doge = game.Workspace.Doge
local dogePrimary = doge.PrimaryPart
local CF = doge:GetPivot()
local eatingSound = doge.eatingSound
local modelTweening = require(script.modelTweening)
local boughtBlocks = game.ReplicatedStorage.Events.PlayerBoughtBlocks
local cooldownText = doge.primary.BillboardGui.TextLabel
local badgeId = 3172462910459354

local badgeService = game:GetService("BadgeService")

local function getRandomBrickColor()
	local randomR = math.random(0, 255) / 255
	local randomG = math.random(0, 255) / 255
	local randomB = math.random(0, 255) / 255
	local randomColor = Color3.new(randomR, randomG, randomB)
	local brickColor = BrickColor.new(randomColor)
	return brickColor
end

proxPrompt.Triggered:Connect(function(player)
	proxPrompt.Enabled = false
	local feedInfo = TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
	local feedTween = TweenService:Create(food, feedInfo, {Size = Vector3.new(3.052, 1.226, 3.056), Position = Vector3.new(-67.391, 84.484, 74.823)})
	feedTween:Play()
	feedTween.Completed:Wait()
	task.wait(1)
	doge:PivotTo(CFrame.new(-67.374, 86.634, 76.311) * CFrame.Angles(math.rad(-60), 0, 0))
	local eatingInfo = TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
	local eatingTween = TweenService:Create(food, eatingInfo, {Size = Vector3.new(3.052, 0.001, 3.056), Position = Vector3.new(-67.391, 83.872, 74.823)})
	eatingTween:Play()
	eatingSound:Play()
	eatingTween.Completed:Wait()
	eatingSound:Stop()
	task.wait(1)
	doge:PivotTo(CFrame.new(-67.374, 86.634, 78.839) * CFrame.Angles(0, math.rad(-90), 0))
	task.wait(1)
	local dogeBlockSpawningInfo = TweenInfo.new(3, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
	modelTweening.TweenModulePosition(doge, dogeBlockSpawningInfo, Vector3.new(-0.76, 86.634, -11.969))
	task.wait(4)
	local newPart = Instance.new("Part")
	newPart.Size = Vector3.new(3, 3, 3)
	newPart.BrickColor = getRandomBrickColor()
	newPart.Position = Vector3.new(math.random(80, 160), 80, math.random(-50, 50))
	newPart.Parent = game.Workspace
	player:WaitForChild("leaderstats"):WaitForChild("Blocks").Value += 1
	boughtBlocks:FireAllClients("Doge just bought a block because "..player.Name.." fed him!", "#e1b303")
	badgeService:AwardBadge(player.UserId, badgeId)
	task.wait(2)
	modelTweening.TweenModulePosition(doge, dogeBlockSpawningInfo, Vector3.new(-67.374, 86.634, 78.839))
	task.wait(3)
	doge:PivotTo(CFrame.new(-67.374, 86.634, 78.839) * CFrame.Angles(0, 0, 0))
	local amountOfTimeLeft = 900
	cooldownText.Visible = true
	for i = 1, 900 do
		task.wait(1)
		amountOfTimeLeft -= 1
		cooldownText.Text = "Doge is full! Wait "..amountOfTimeLeft.." seconds to feed him again."
	end
	proxPrompt.Enabled = true
	cooldownText.Visible = false
	boughtBlocks:FireAllClients("Doge wants food! If you feed him, he'll give you a prize!", "#e1b303")
end)

Don’t use tweens to move anything with humanoids or anything meant to mimic real things. Use pathfindingservice instead. Also, please PLEASE organize your code. Looking through code is much much harder when every line is clumped up together with no gaps. As for this, I don’t know what you mean by “falling apart”, do you mean the parts disconnect?

The picture shows exactly what happens.

I’ve decided to just rewrite the script instead. Thanks for the help anyway.

Just so you know for the future: tweening the position of a part will not update its assembly. This is because CFrame updates are handled differently in comparison to Position updates. I don’t believe anything has changed from when I tested this (in August of last year).

Tweening Position:

Tweening CFrame: