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)
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)