Tweening Primary Part Issue

I’m trying to tween a model so I would have to tween the primary part, i am tweening the primary part with weldconstraints and all it is tweening is the primary part.

Tween part

local function tweenToPosition(part)
		if model then
			local primaryPart = model.PrimaryPart
			local goal = {}
			goal.CFrame = CFrame.new(part.Position)

			local tweenInfo = TweenInfo.new(
				0.5,
				Enum.EasingStyle.Quad,
				Enum.EasingDirection.Out, 
				0,
				false,
				0 
			)

			local tween = TweenService:Create(primaryPart, tweenInfo, goal)
			tween:Play()
		end
	end

	local function onInput(input, gameProcessedEvent)
		if input.UserInputType == Enum.UserInputType.MouseMovement then
			local hit = game:GetService("Players").LocalPlayer:GetMouse().Target
			if model then
				if hit and hit:IsDescendantOf(model) then
					if not highlight then
						highlight = game.ReplicatedStorage.MergingSystemMain.Highlight:Clone()
						highlight.Parent = model
					end
				else
					if highlight then
						highlight:Destroy()
						highlight = nil
					end
				end

				if isDragging then
					local mousePosition = input.Position
					local ray = camera:ScreenPointToRay(mousePosition.X, mousePosition.Y)
					local worldPosition = ray.Origin + ray.Direction * ((-0.9 * ray.Origin.Y) / ray.Direction.Y)

					local groundHeight = 0
					local groundRay = Ray.new(worldPosition, Vector3.new(0, -1, 0) * 1000)
					local groundPart, groundPos = workspace:FindPartOnRayWithIgnoreList(groundRay, {model})
					if groundPart then
						groundHeight = groundPos.Y
					end
					if worldPosition.Y < groundHeight + model.PrimaryPart.Size.Y / 2 then
						worldPosition = Vector3.new(worldPosition.X, groundHeight + model.PrimaryPart.Size.Y / 2, worldPosition.Z)
					end

					model:SetPrimaryPartCFrame(CFrame.new(worldPosition))
				end
			end
		end
	end

	local function onInputEnded(input, gameProcessedEvent)
		if input.UserInputType == Enum.UserInputType.MouseButton1 then
			isDragging = false
			if model then
				for _, part in pairs(model:GetDescendants()) do
					if part:IsA("BasePart") then
						part.CanCollide = true
					end
				end

				local closestPart = nil
				local closestDist = math.huge

				for _, part in pairs(boatSpotsFolder:GetChildren()) do
					if part:IsA("BasePart") and part.CanCollide then
						if model then
							local dist = (model.PrimaryPart.Position - part.Position).Magnitude
							if dist < closestDist then
								closestPart = part
								closestDist = dist
							end
						end
					end
				end

				if closestPart then
					tweenToPosition(closestPart)
				end
			end
		end
	end

Make sure all the parts welded to the primary part are unanchored, and i would suggest using welds instead of weldconstraints.

Hey I would reccomend using the rigEditor plugin to make sure all your welds are set up properly so they respect the primarypart they are rotating on. So everything should be unahored. Wiith th plugin select the part you wish to rotate first then select everything else at once using shift. At this point either weld them together or use joints. Now when you rotate the model from that primary point they will respect it because it is part0 of the weld. I never used weld constraints but RIgEditor lite plugin the popular one is really good for this application.

1 Like

Am I able to tween an object that has a weld constraint?

I don’t know but the RigEditor plugin will make it so you can animate your assembly or just add welds to it in seconds. you don’t have to worry about deleting the weldconstraints. Yes you can provided they are set up properly. Also make sure you are tweening the CFrame of the object not the position using the position has been know to break welds.

They are all right, and its using CFrame. Still not working

I’m afraid you are missing something my friend cause this is a common thing we devs make. I have tried using weld constraints before and ran into your issue so I would just reccomend using welds or joints and the RigEditor plugin.

Look at this video you will be able to see what is happening Water Merge Game - Roblox Studio (gyazo.com)

You are moving it with the studio editor while it is tweening. So of course its going to break the tween is changing the position but you are conflicintg it with the studio tools… You could make a function to find when the mousebutton1 is clicked down and fire a function to the server to cancel the tween.
the tween would have to be defined globally
local tween=nil
tween=TweenService:Create()
tween:Cancel()

What do you mean, the only thing that is breaking is the part on top of the boat isnt tweening with it.

Unanchor all parts that are not the primary part
Weld all parts to the primary part then use this (You can use moon animator weld for this)
Then use a server-script inside the primary part

local part = script.Parent -- script.Parent.PrimaryPart
local pos = Vector3.new(0,0,0) -- Your position.
local TweenService = game:GetService("TweenService")
local rot = part.CFrame - part.CFrame.Position
game:GetService("TweenService"):Create(part, TweenInfo.new(...), {CFrame = CFrame.new(pos) * rot}):Play()

That works thank you for helping.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.