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

Holding a Position while manipulating it...?

How could I make it so the position of this ImageLabel is always "UDim2.new(0.5, -210, 0.5, -210)" -- Middle of the screen

but at the same time, this function is working:

SSLogo.Position = UDim2.new(0.5, math.sin(tick() * 100), 0.5,  math.sin(tick() * 100))

2 comments

0

What does that mean? How can something be at two places at once? Specify what you mean better.

0

I want the ImageLabel to be shaking in the middle of the screen. It's hard to do that when you can't set the position of where the "math.sin(tick() * 100)" is.

1 answer

✓ Accepted answer

Of course you can set the position simply.


Think about (.5, -210, .5, -210) as a position.

I will use this definition for brevity:

local wave = math.sin(tick() * 100)

Think of the wave contributing to a displacement -- not a position on the screen, but an amount to move. But a displacement on its own isn't a position. position + displacement --> position. So we have to separate the position and displacement in the code you provided. Then we'll just change the position to the new one.

-- The original:
UDim2.new(0.5, wave, 0.5,  wave)
-- Equivalent:
UDim2.new(0.5, 0 + wave, 0.5, 0 + wave)
-- Equivalent:
UDim2.new(0.5, 0, 0.5, 0) + UDim2.new(0, wave, 0, wave)
-- position + displacement

Thus we just use instead

UDim2.new(.5, -210, .5, -210) + UDim2.new(0, wave, 0, wave)

-- or, if you prefer,
UDim2.new(.5, -210 + wave, .5, -210 + wave)

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