How to add position to a UI element

Hello! I am trying to make my UI have a fade in effect (it flys up and fades in)

The one issue I am having is trying to add position (making the Y scale go from 0.85 > 0.9)

I tried to use Position.Scale.Y to try to make it work but it didn’t.

Does anybody know how to do it?

The code is here:

local StatusCall = game.ReplicatedStorage.StatusMessage
local player = game.Players.LocalPlayer
local Enabled = player.Backpack.KeybindFlashlight.HasFlashlight

StatusCall.OnClientEvent:Connect(function()
	if Enabled == true then
		script.Parent.Text = "You already have this."
		
	else
		
		script.Parent.Text = "You have gained: 'Flashlight'"
	end
	script.Parent.Position = UDim2.new(0.5,0,0.9,0)
	for i = 1,10 do
		script.Parent.TextTransparency += 0.1
		script.Parent.Position.ScaleY += 0.015
	end
	
	wait(5)
	
	for i = 1,10 do
		script.Parent.TextTransparency -= 0.1
	end
end)

Any help is appreciated!

2 Likes

the code i used was edited to stuff i found, but forgot to revert it back

I recommend using TweenService

Example:

local TweenService = game:GetService("TweenService")

local ThisText = -- Instance

local AnimateInfo = TweenInfo.new(
1, -- Interval
Enum.EasingStyle.Sine, -- Style
Enum.EasingDirection, -- Direction for animation (Check the Hub for more info)
0, -- Repeat count (-1 for infinite repeat)
false, -- Reverse
0 -- Delay time
)

local Goal = {
   -- Properties that you will animate
    Position = UDim2.new(1, 0, 1, 0),
    Size = UDim2.new(1, 0, 1, 0),
    TextTransparency = 1,
}

local AnimateThis = TweenService:Create(ThisText, AnimateInfo, Goal)

AnimateThis:Play() -- Run
1 Like

script.Parent.Position.ScaleY += 0.015

Instead of assigning the Y scale value directly, try adding a Udmi2 position to it.
script.Parent.Position += UDim2.fromScale(0, 0.015)

Ideally you should use a tween to handle UI animations.

1 Like

You can’t override/assign the components of a UDim2 value with doubles (double precision values), you need to construct a new UDim2 value instead.

guiObject.Position += UDim2.new(0.5, 0, 0.5, 0)
guiObject.Size += UDim2.new(0.5, 0, 0.5, 0)