How to do the opposite of a tween

I have this code that moves the camera to a part

local set = TweenInfo.new(1.5,
		Enum.EasingStyle.Quart, 
		Enum.EasingDirection.InOut,
		0,
		false,
		0
	)
	local target = {CFrame = workspace.BlackMarketCam.CFrame}
	local tweenStart = TweenService:Create(cc, set, target)
	tweenStart:Play()

How can I do the opposite of the code that I just did. This might feel stupid to say but I don’t know how to, because whatever code I attempt to achieve this there will be a error saying Unable to cast to dictionary.

Thank you for reading.

What do you mean by opposite? Like going back to the original spot it started at?

yes, sorry about the misunderstanding

local startPos = workspace.BlackMarketCam.CFrame

local set = TweenInfo.new(1.5,
	Enum.EasingStyle.Quart, 
	Enum.EasingDirection.InOut,
	0,
	false,
	0
)
	local target = {CFrame = workspace.BlackMarketCam.CFrame}
	local tweenStart = TweenService:Create(cc, set, target)
	tweenStart:Play()

-- wait to do whatever

local set = TweenInfo.new(1.5,
	Enum.EasingStyle.Quart, 
	Enum.EasingDirection.InOut,
	0,
	false,
	0
)
	local target = {CFrame = startPos}
	local tweenStart = TweenService:Create(cc, set, target)
	tweenStart:Play()

This saves where it starts and goes there.

2 Likes

In your TweenInfo, there is an argument which makes the tween reverse back to its original spot on completion. Maybe replace the false boolean in the TweenInfo with true

I think a better solution would be to just change the reverses boolean to have it go back after it reaches that point.

local set = TweenInfo.new(1.5,
	Enum.EasingStyle.Quart, 
	Enum.EasingDirection.InOut,
	0,
	true, --reverses
	0
)

Edit: I didn’t see doge_alt7’s post when I wrote this, but yeah this is basically what he said.

Doesn’t this make it to where it immediately goes back to the starting position?

It goes back once it reaches your goal, but yeah, the way you did it allows you to add a delay.

I believe he is trying to make a shop, so I implemented the pause if the player needs to have their camera facing the shop, then once they are done, move back.

Uperscuzzi is right, I don’t want it to immediately go back tot he starting position

If I helped, please mark my reply as the solution! I hope you have fun making your game!

um there was an error saying that it was unable to cast to dictionary…

send a screenshot of your console output please

image
sorry for the wait

What is the cc variable for? It’s in this line:

local tweenStart = TweenService:Create(cc, set, target)

cc stands for currentcamera in this script

What is the code found at line 95?

Are you making the camera scriptable before running the tween?

yes I did, the error would still display though


this is the code, i swapped around the target and cc because I want target (which is the BlackMarketCamera) to the current camera of the player. That is the issue