How can I make this tween text script efficient

I have a function which either tweens the text up or down depending where the mouse is, if it enters the text goes up but if the mouse leaves the box it goes down.

I have a problem with once it enters it takes multiple times for the arrow to go out of the box so that the text can come back down so I need help how I either can reverse it or how I can cancel it or something

	TweenNameFrame(script.Parent.Parent.GunType, "up")

	TweenNameFrame(script.Parent.Parent.GunType, "down")
function TweenNameFrame(frame, State)
	if State == "up" then
		frame:TweenPosition(, 0,-0.265, 0))
		frame:TweenPosition(, 0,0.43, 0))

I know that you can cancel a tween that is created by TweenService, since it returns a Tween object when you use :Create(). I don’t know if TweenPosition works in the same way though, so you might be forced to use TweenService.


local TweenService = game:GetService("TweenService")
local tweenInfo =
	2, -- Time
	Enum.EasingStyle.Linear, -- EasingStyle
	Enum.EasingDirection.Out, -- EasingDirection
	0, -- RepeatCount (when less than zero the tween will loop indefinitely)
	false, -- Reverses (tween will reverse once reaching it's goal)
	0 -- DelayTime
local tween = TweenService:Create(tweenInfo, Position =, 0,-0.265, 0)}
tween:Play() --play

tween:Cancel() -- cancel

Using this method you could cancel, then play a tween in the other direction.

Another option would be to just change the .Position manually, instead of using tweens. This would only be practical if you are Tweening as simply as linearly, or exponentially.

1 Like