CFrame tween not working, why?

Why does this not work, can someone tell me what I am doing wrong?

for i, v in next, workspace:GetDescendants() do
	if v:IsA("SpawnLocation") then
		local newpos = v.CFrame * Vector3.new(0,v.Size.Y/2+30,0)
	end
end
local TweenService = game:GetService("TweenService")
			local part = game.Players.LocalPlayer.Character.HumanoidRootPart -- Change to the part you want to tween
			part.Anchored = true

			local info = TweenInfo.new(
				5,                      -- Time it will take
				Enum.EasingStyle.Sine,     -- Easing style
				Enum.EasingDirection.InOut,   -- Easing direction
				0,                         -- Repeat count
				false,                     -- Reverses
				0                          -- Delay
			)

			local goals = {CFrame = newpos}

			local tween = TweenService:Create(part, info, goals)
			tween:Play()
			wait(5)
			part.Anchored = false
1 Like

I may be wrong, but change CFrame in goals to Position.

This:

local goals = {CFrame = newpos}

To this:

local goals = {Position = newpos}

I did a test and when I my CFrame, like what you did here:

by a vevtor3, it change it from CFrame to vector3.

Idk what you’re exactly doing with this, but if this is a Script there is no way to obtain the LocalPlayer

If it’s a LocalScript, I’d recommend waiting for the Character’s HumanoidRootPart to properly load in time cause there might be a chance that it may not work & result back an error:

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

You’re trying to reset the variable for every SpawnLocation there is in the entire workspace, unless if you have like some sort of table you can loop through it’ll only just Tween the most recent newpos variable to that CFrame

local Positions = {}

for _, Object in pairs(workspace:GetDescendants()) do
    if Object:IsA("SpawnLocation") then
        table.insert(Positions, Object.CFrame * Vector3.new(0, Object.Size.Y / 2 + 30), 0)
    end
end

Honestly I am confused about what the intended behavior should be. Although if the goal is to tween the player to every spawn one by one this should probably work:

--LocalScript/Script inside StarterCharacterScripts
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")

local Character = script.Parent

function tween(newpos)
	local part = Character.HumanoidRootPart 
	part.Anchored = true
	local info = TweenInfo.new(
		5,                      -- Time it will take
		Enum.EasingStyle.Sine,     -- Easing style
		Enum.EasingDirection.InOut,   -- Easing direction
		0,                         -- Repeat count
		false,                     -- Reverses
		0                          -- Delay
	)
	local goals = {CFrame = newpos}
	local tween = TweenService:Create(part, info, goals)
	tween:Play()
	task.wait(5)
	part.Anchored = false
end

--use pairs when looping through objects
for i, v in pairs(workspace:GetDescendants()) do
	if v:IsA("SpawnLocation") then
		--you can't multiply vectors with CFrames!, instead make the vector a CFrame
		local pos = Vector3.new(0,v.Size.Y/2+30,0)
		local newpos = v.CFrame * CFrame.new(pos)
		--the tween code should be run inside the loop, else it will break 
		tween(newpos)
	end
end
for i, v in next, workspace:GetDescendants() do
	if v:IsA("SpawnLocation") then
		local newpos = v.Position + Vector3.new(0,v.Size.Y/2+30,0)
	end
goal = {
CFrame = CFrame.new(newpos)
}

if it’s model weld all parts to main part first and Anchor only main or if it’s part you can just use

goal = {
Position = newpos
}