Model won't tween

Im making spikes that appear from the ground as a obstacle for my obby, I cant get it to tween though, could anyone please help me out?

the spikes:

the code that I used:

local TweenService = game:GetService("TweenService")
local MovingObs = game.Workspace:FindFirstChild("MovingObstacles")
local spikeFolder = MovingObs:WaitForChild("SpikeTrap")
local spikesModel = spikeTrap:WaitForChild("Spikes")

local function tweenSpikeModel(spike)
    local CF_v = Instance.new("CFrameValue")
    CF_v.Changed:Connect(function(V)
        spike:SetPrimaryPartCFrame(V)
    end)

    CF_v.Value = spike:GetModelCFrame()

    local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, -1, true)
    local endCFrame = spike:GetModelCFrame() + Vector3.new(0, -6, 0)

    local tween = TweenService:Create(CF_v, tweenInfo, {Value = endCFrame})
    tween:Play()
end

local function onSpikeTouch(hit)
    local char = hit.Parent
    local humanoid = char:FindFirstChild("Humanoid")
    if humanoid then
        humanoid:TakeDamage(50)
    end
end

for _, spike in ipairs(spikesModel:GetChildren()) do
    if spike:IsA("Model") then
        tweenSpikeModel(spike)

        for _, part in ipairs(spike:GetChildren()) do
            if part:IsA("BasePart") then
                part.Touched:Connect(onSpikeTouch)
            end
        end
    end
end

GetModelCFrame is not a valid method. The output should have detected that, so please check for any errors there next time.

Instead, you can use GetPivot to get the model’s CFrame and I suggest you to use PivotTo to set it instead of SetPrimaryPartCFrame.

local function tweenSpikeModel(spike)
    local CF_v = Instance.new("CFrameValue")
    CF_v.Changed:Connect(function(V)
        spike:PivotTo(V)
    end)

    CF_v.Value = spike:GetPivot()

    local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, -1, true)
    local endCFrame = spike:GetPivot() + Vector3.new(0, -6, 0)

    local tween = TweenService:Create(CF_v, tweenInfo, {Value = endCFrame})
    tween:Play()
end

didn’t work for me, I tried many variations of trying to tween it, nothing worked

If all the spikes are moving at the same time, make one of them Anchored and weld the others to it but make sure they are unanchored.

Set all your tweeninfo stuff before your functions. They aren’t going to change.

Here’s some sections of code I used.
In the beginning, before the function:

local tweenService = game:GetService("TweenService")

local gate = script.Parent.Parent.Gate.Solid   -- Solid is the Anchored Part I'm tweening

local goalUp = {}
goalUp.CFrame = gate.CFrame * CFrame.new(0, 0, 0)
local goalDown = {}
goalDown.CFrame = gate.CFrame * CFrame.new(0, -2.35, 0)

local tweenInfoGate = TweenInfo.new(
	6,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.InOut
	)

local tweenUp = tweenService:Create(gate, tweenInfoGate, goalUp)
local tweenDown = tweenService:Create(gate, tweenInfoGate, goalDown)

Then when I want to move it I just call
tweenUp:Play()
or
tweenDown:Play()
inside the function.

logic looks good to me and the output should catch any errors, are you sure your script is running where its at? swap RunContext off default

if it is indeed running, fill it & debug with Print()s and you should find problems in a mintute or so

I used WeldConstraints for my other obstacle, Im trying to do the same thing with my spikes, for some reason, only the primary part moves, but the other parts i welded to the primary do not work properly.

Swinging ball:


Workspace of the ball:
image

Spike:

Current script for the spike:

local TweenService = game:GetService("TweenService")
local model = game.Workspace:WaitForChild("Spike")

local primaryPart = model.PrimaryPart
if not primaryPart then
	print("no primary")
	return
end

local tweenInfo = TweenInfo.new(
	2,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.InOut,
	-1,
	true
)

local startPosition = primaryPart.Position
local targetPosition = startPosition + Vector3.new(0, 4, 0)

local goal = {Position = targetPosition}

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

tween:Play()local TweenService = game:GetService("TweenService")
local model = game.Workspace:WaitForChild("Spike")

local primaryPart = model.PrimaryPart
if not primaryPart then
	print("no primary")
	return
end

local tweenInfo = TweenInfo.new(
	2,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.InOut,
	-1,
	true
)

local startPosition = primaryPart.Position
local targetPosition = startPosition + Vector3.new(0, 4, 0)

local goal = {Position = targetPosition}

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

tween:Play()

Video of the spike:

If you’d like more information, please let me know

Only the tweened Part should be anchored. Anything else has to be unanchored.
If they are in the baseplate you may need to put the baseplate (or other obby parts) and the spikes in a CollisionGroup that doesn’t collide with itself.

everything that isnt the tweened part is unanchored

Then try it with all the spike welded parts CanCollide false to see if there’s a collision issue.

Just an extra comment as well. Why are you using a second Damage Part? Shouldn’t touching just the cone do the damage?

woops, accidentally clicked solution, the main game idea is a car obby, meaning that I will need many spikes to do that, might aswell make it simple to make the damage part like that so i dont have to find children in the model and give them each the damage ability

For that you could use Tags or Attributes in each of the spikes.

Please read all the questions and suggestions in a post. I’ve seen a couple of items that you haven’t confirmed.

  • @puffo suggested prints (print variables or items like goal, not just “this worked” or “moved”).
  • I suggested making all the Parts CanCollide false in my previous post.

Also are you sure your welds are active? In the Model tab under Constraints click the Show Welds button. There should be green weld lines running between unanchored items. Grey lines indicate items welded to an anchored item. If there are no visual welds then click the Part0 and Part1 in the WeldConstraint Properties and reclick each Part they are supposed to be joined to.