Tween goes lower than expected value

It’s supposed to go back to its original position, which is why I made the Vector3 changes add up to 0. What’s wrong with my code?

local crusher = script.parent
local TweenService = game:GetService("TweenService")
local CFrame = script.parent.CFrame


local crushinfo = TweenInfo.new(
	2, -- Time animating
	Enum.EasingStyle.Linear, -- EasingStyle
	Enum.EasingDirection.Out, -- EasingDirection
	0, -- Repitions
	false, -- Reverse post tween?
	0 -- Delay time
)

local resetinfo = TweenInfo.new(
	5, -- Time animating
	Enum.EasingStyle.Linear, -- EasingStyle
	Enum.EasingDirection.In, -- EasingDirection
	0, -- Repitions
	false, -- Reverse post tween?
	0 -- Delay time
)

local crushgoal = {
	CFrame = crusher.CFrame + Vector3.new(0, -22, 0)
}

local resetgoal = {
	CFrame = crusher.CFrame + Vector3.new(0, 22, 0)
}


local crush = TweenService:Create(crusher, crushinfo, crushgoal)
local reset = TweenService:Create(crusher, resetinfo, resetgoal)

while true do
	wait(5)
	reset:play()
	wait(6)
	crush:play()
end
1 Like

It could be issues with timing, I recommend usiung tween.Completed:Wait() instead of waiting the duration of the tween and see if that fixes it.

	reset:play()
    reset.Completed:Wait()
	crush:play()
    crush.Completed:Wait()

I appreciate the effort but unfortunately that did not work

local TweenService = game:GetService("TweenService")

local crusher = script.Parent
local origPos = crusher.Position

local crushinfo = TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
local resetinfo = TweenInfo.new(5, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)

local crushgoal = {Position = origPos + Vector3.new(0, 22, 0)}
local resetgoal = {Position = origPos}

local crush = TweenService:Create(crusher, crushinfo, crushgoal)
local reset = TweenService:Create(crusher, resetinfo, resetgoal)

while true do
	crush:Play()
	crush.Completed:Wait()
	reset:Play()
	reset.Completed:Wait()
end

The issue is that when you declared the goals for the tween, you used crusher.CFrame, which actually remembers the crusher’s CFrame when those lines of code were executed, and it does not set the goal based on the crusher’s CFrame at the time of tweening. Basically, you just declared the goal as 22 studs above it’s original position, and it’s resetting point as 22 studs below it’s original position. Forummer’s code is correct, but I think they typed the crush goal as above instead of below

1 Like

The main issue was overriding the CFrame class itself at the top of the script.

The script worked perfectly after I made that fix. Thanks!