Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I set the time of a tween / prevent the tween from ending?

I have this simple tween here where it goes in when the mouse hovers on it, the trouble is, if the mouse leaves before it's finished the first tween, it won't tween out. Can anyone tell me a fix for this please, or a way to set the time?

script.Parent.MouseEnter:Connect(function()
	script.Parent:TweenSizeAndPosition(UDim2.new(0.6, 0,0.06, 0),UDim2.new(0.2, 0,0.106, 0))
end)
script.Parent.MouseLeave:Connect(function()
	script.Parent:TweenSizeAndPosition(UDim2.new(0.78, 0,0.072, 0),UDim2.new(0.11, 0,0.096, 0))
end)

Thanks!

1 comment

0

nvm I know how to set the time but how can I prevent the other thing?

2 answers

Use TweenService:Create() instead because this will return Tween and you can control the Tween to Play() when mouse enter and Cancel() when mouse leave.

local TweenService = game:GetService("TweenService")

local TweenTime = 1 -- set the tween time

local goal = {

In = {Size = UDim2.new(0.78, 0,0.072, 0, Position = UDim2.new(0.11, 0,0.096, 0)},
Out = {Size = UDim2.new(0.6, 0,0.06, 0), Position = UDim2.new(0.2, 0,0.106, 0)}

}

local TweenIn = TweenService:Create(script.Parent,TweenInfo.new(TweenTime),goal.In)
local TweenOut = TweenService:Create(script.Parent,TweenInfo.new(TweenTime),goal.Out)

script.Parent.MouseEnter:Connect(function()
	TweenIn:Cancel()
	TweenIn:Play()
end)
script.Parent.MouseLeave:Connect(function()
	TweenIn:Cancel()
	TweenOut:Play()
end)

You can set Tween Override To true by this way:

script.Parent.MouseEnter:Connect(function()
    script.Parent:TweenSizeAndPosition(UDim2.new(0.6, 0,0.06, 0),UDim2.new(0.2, 0,0.106, 0), "In", -- or out depend on u
"Linear", -- Default EasingStyle I think
1, -- The time
true -- Important Part: Set overide to true)
end)
script.Parent.MouseLeave:Connect(function()
    script.Parent:TweenSizeAndPosition(UDim2.new(0.78, 0,0.072, 0),UDim2.new(0.11, 0,0.096, 0),
"In", -- or out depend on u
"Linear", -- Default Style of tweening i think
1, -- The time
true -- Important Part: Set overide to true))
end)

Hope that helped! Here is a article about EasingStyle

This discussion is preserved as it was. New answers, comments, and votes are closed.