How to make model/part tweens back to original size

  1. What do you want to achieve? Keep it simple and clear!
    I want to tweens model back to its original size
  2. What is the issue? Include screenshots / videos if possible!

    When I tween it keeps getting smaller smaller then disappear
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Tried but I don’t know a way to save its original size

function onClicked()
	local egg = workspace.egg
	local eggSize = egg.Size
	
	game.TweenService:Create(egg, TweenInfo.new(.1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 1, false, 0), 
		{Size = eggSize*0.5}
	):Play()
	
	
end
 

script.Parent.ClickDetector.MouseClick:connect(onClicked)

You can utilize the reverse property of TweenInfo for this, debounce should also be added to prevent people from spamming. Here is a quick recreation of the script:

local debounce = false

function onClicked()
	if debounce then return end
	debounce = true
	local egg = workspace.egg
	local eggSize = egg.Size

	local tween = game.TweenService:Create(egg, TweenInfo.new(.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, true), {Size = eggSize*0.5})
	tween:Play()
	tween.Completed:Wait()
	debounce = false
end


workspace.egg.ClickDetector.MouseClick:connect(onClicked)

Also if you are looking for something that tweens the part back to its original size after it has shrinked, use something like this (sorry I might have misunderstood):

local egg = workspace.egg

local debounce = false
local shrinked = false
local eggSize = egg.Size

function onClicked()
	if debounce then return end
	debounce = true

	local tween
	if shrinked then
		shrinked = false
		tween = game.TweenService:Create(egg, TweenInfo.new(.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {Size = eggSize})
	else
		shrinked = true
		tween = game.TweenService:Create(egg, TweenInfo.new(.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {Size = eggSize*0.5})
	end
	tween:Play()
	tween.Completed:Wait()
	debounce = false
end


workspace.egg.ClickDetector.MouseClick:connect(onClicked)
1 Like

Store the egg’s size beforehand:

local egg = workspace.egg
local eggSize = egg.Size
function onClicked()
	game.TweenService:Create(egg, TweenInfo.new(.1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 1, false, 0), 
		{Size = eggSize*(egg.Size.Magnitude < eggSize.Magnitude and 2 or 0.5)}
	):Play()
	
	
end
 

script.Parent.ClickDetector.MouseClick:connect(onClicked)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.