I created a ModuleScript
to be called to tween a part to the middle of the screen, but it doesn't tween to the desired location. Intead of {0.402, 0},{0.467, 0}
, it tweens to {0, 0}, {0, 0}
. I'm not sure what I'm doing wrong here. Thank you in advance.
```lua
local module = {}
function module.load()
local TweenService = game:GetService("TweenService") local tweenInfo = TweenInfo.new( 2.5, -- Time Enum.EasingStyle.Sine, -- EasingStyle Enum.EasingDirection.InOut, -- EasingDirection 0, -- RepeatCount (when less than zero the tween will loop indefinitely) false, -- Reverses (tween will reverse once reaching it's goal) 0 -- DelayTime ) TweenService:Create(script.Parent.TextLabel, tweenInfo, {Position=UDim2.new({0.402, 0},{0.467, 0})}):Play() wait(5.5) TweenService:Create(script.Parent.TextLabel, tweenInfo, {Position=UDim2.new({0.402, 0},{-1, 0})}):Play() wait(2.5) script.Parent:Destroy()
end
return module ```
Hey there!
Ok, instead of using TweenSerivce
to tween the TextLabel's position, you can use the function TweenPosition()
which is used for all GuiObjects
.
TextLabel:TweenPosition(UDim2.new(XScale,XOffset,YScale,YOffset),EasingDirection,EasingStyle,AmountOfTime,Override)
or use click on the TweenPosition()
function link I gave above, and I see that you are using brackets ({}
) inside the UDim2 position. In Lua, brackets are known as tables, and it wouldn't be correct to have a table in a function that only accepts numbers. If you still wanted to use a table, you could use unpack()
:
TextLabel:TweenPosition(UDim2.new(unpack({XScale,XOffset,YScale,YOffset}),EasingDirection,EasingStyle,AmountOfTime,Override))
I hope I helped.