Needing help with TweenService

Ok, I’ll try to make this really easy to understand. I want to tween a rig (model) to a certain location (model). Here’s my code (ignore the top part).

local tweenService = game:GetService("TweenService")

local function appear()
	-- Define variables
	local stand = workspace.Stand
	local firstLoc = stand.Spawn
	local spots = stand.Spots
	local rigs = game.ReplicatedStorage:WaitForChild("Rigs")
	-- Select a rig --
	local rigNum = math.random(1,3)
	local rigType
	
	for i, rig in ipairs(rigs:GetChildren()) do
		if i == rigNum then
			rigType = rig
		end
	end
	
	-- Select a location --
	for i, newLoc in ipairs(spots:GetChildren()) do
		if newLoc:GetAttribute("Taken") == false then
			
			-- Spot is open, spawn rig --
			newLoc:SetAttribute("Taken", true)
			local newRig = rigType:Clone()
			newRig.Parent = workspace
			newRig:PivotTo(firstLoc:GetPivot())
			
			-- Get item's pivots --
			local rigPivot = newRig:GetPivot()
			local locPivot = newLoc:GetPivot()
			
			-- Find magnitute and time
			local mag = (rigPivot.Position - locPivot.Position).magnitude
			local duration : number = mag / 8
			
			-- Make tween info --
			local tweenInfo = TweenInfo.new(duration, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)
			local goal = {rigPivot = locPivot}
			
			-- Make tween and play --
			local tween = tweenService:Create(newRig, tweenInfo, goal)
			tween:Play()
			tween.Completed:Wait()
			
		end
	end
end

return appear

When run, I get this error:


If anyone knows a fix, please respond ASAP! Anything helps!

1 Like

post bump (its been 15 minutes and i’m very impatient sorry about that)

local goal = {rigPivot = locPivot}

Because “rigPivot” is not a property of Model.

Sorry, I could not understand your response. Could you please explain more?

The table “goal” requires you to put in properties that you want to tween with their final value. “rigPivot” can’t be tweened because it’s simply not an existent property. Read the documentation for more information on how to use TweenService:

1 Like

Alright, I changed rigPivot to Pivot, but I now get this error:


Do you know why this happens?

You cant tween the pivot of the model since it isn’t a property of the model. Try tweening the primary part of the model [Once you weld all the parts of the model to it](e.g. the hmr)

local duration : number = mag / 8
			
			-- Make tween info --
			local tweenInfo = TweenInfo.new(duration, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)
			local goal = {CFrame = locPivot}
			
			-- Make tween and play --
			local tween = tweenService:Create(newRig.PrimaryPart, tweenInfo, goal)
			tween:Play()
			tween.Completed:Wait()

If you dont want to use this to try moving the rig’s humanoid to locPivot.Position

1 Like

You cannot use variables for property names, and you cannot change the pivot variables of a model, use CFrame instead. Here is a code snippet if you are looking to tween a model:

local tweenService = game:GetService(“TweenService”)
local info = TweenInfo.new()

local function tweenModel(model, CF)
local CFrameValue = Instance.new(“CFrameValue”)
CFrameValue.Value = model:GetPivot()

CFrameValue:GetPropertyChangedSignal(“Value”):Connect(function()
model:PivotTo(CFrameValue.Value)
end)

local tween = tweenService:Create(CFrameValue, info, {Value = CF})
tween:Play()

tween.Completed:Connect(function()
CFrameValue:Destroy()
end)
end
From post: Any way to tween a model via TweenService? - #9 by tunicus, changed deprecated functions GetPrimaryPartCFrame and SetPrimaryPartCFrame.

If you are looking to move a rig with a humanoid, you may be able to use humanoid:MoveTo() Instead.

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