Tween Positions

Hello readers! My name is Dev_Cron aka Cron. I’m a Builder/Scripter. And I’d like to get someone help in the following script.

What happened?

I made a part with TweenPosition. When you click the part it will do Tween. It’s working with ClickDetector. My question is what can I add to the script that if I click it again the tween will change from + Vector3.new(0, 0, 8) to - Vector3.new(0, 0, 8) ?

The current script:

local ClickDetector = script.Parent.ClickDetector

local Part = script.Parent.Parent.ForTest

local TweenService = game:GetService("TweenService")

ClickDetector.MouseClick:Connect(function(click)

wait()

local PartTween = TweenService:Create(Part, TweenInfo.new(1), {Position = Part.Position - Vector3.new(0, 0, 8)})

PartTween:Play()

end)
1 Like

First, i’ll let you know that Tween:Stop() also exists,

Then, i don’t know how you want to proceed, but considering the second position is just the opposite, let’s say it’s a ON/OFF Button :

local ClickDetector = script.Parent.ClickDetector
local Part = script.Parent.Parent.ForTest
local TweenService = game:GetService("TweenService")
local Switch = false

local TweenOn = TweenService:Create(Part, TweenInfo.new(1), {Position = Part.Position - Vector3.new(0, 0, 8)})
local TweenOff = TweenService:Create(Part, TweenInfo.new(1), {Position = Part.Position - Vector3.new(0, 0, -8)})

ClickDetector.MouseClick:Connect(function(click)

if Switch == false then
TweenOn:Play()
TweenOff:Stop()
else
TweenOff:Play()
TweenOn:Stop()
end

Switch = not Switch

end)

There are more efficient (less characters) ways of doing it, but this example should be self explanatory.

1 Like

Hello there, I tried the script and it’s saying this:

image

Yea, i lied to you, :Stop() doesn’t exist

it’s :Cancel()

1 Like