Position Offset not working

Hi, when I set the position of a label it will only show up on the top left of the screen when I’m using a random, I was told the 2nd and 4th things parameter were offset so I would only need 0-1, right? Sorry if this is a stupid question

local re = game:GetService("ReplicatedStorage")
local text = re.EatEffect
local remotes = re.Remotes
local effectEvent = remotes.PlayEffect

effectEvent.OnClientEvent:Connect(function(amount)
	local effect = text:Clone()
	effect.Parent = game.Players.LocalPlayer.PlayerGui.ScreenGui
	effect.Visible = true
	effect.Text = "+"..amount.." Coins"
	effect.Position = UDim2.new(0, math.random(0,1), 0, math.random(0,1))
	for i = 1, 100 do
		wait(0.001)
		effect.TextTransparency = i/100
	end
end)

When you use Udim.new, the first and third values determine your scale, which ensures it propertionally increases or decreases across different screen sizes
For example if you want your label to be at the centre you can set them at 0.5 and 0.5(which represents 50% of your screen height and width)
For example:
Udim2.new(0.5,-50,0.5,25) centres the label, then shifts it to the left by 50pixels and up by 25pixels

You’d also want to scale the offsets values appropriately so that it looks the same on every device(scale = offset/parentsize(in pixels)
You’ll find plenty of resources to understand this online, and if you want I can send you a youtube video link too

Also the offsets are measured in pixels not proportions(if you want to measure them in proportions, you’ll have to scale them like i mentioned before)

1 Like
local screenSize = game.Players.LocalPlayer.PlayerGui.ScreenGui.AbsoluteSize
effect.Position = UDim2.new(0, math.random(0, screenSize.X), 0, math.random(0, screenSize.Y))

you’re using offsets, and that random value will just return 0 or 1 (either on the top-left or bottom-right corners)

first fix the random: (ill be using a function for easier access and clean code)

function getRandom()
	return math.random(0, 100)/100
end

now fix the UDim2

effect.Position = UDim2.new(getRandom(),0,getRandom(),0)

I was wondering how that 1st one was used
effect.Position = UDim2.new(math.random(), 0, math.random(), 0)
Didn’t look right. Trying to consider a mobile also.

I did that and I set both the scales to 0.5 but they will only show up directly in the center

What exactly are you trying to achieve with the label?

it’s basically when I eat a fruit, it fires a remote event and it will show up like “+1 cash”, it’s just an effect

What I assume is that he’s like trying to show how much coins a player got on an event
like you pick up a coin and stuff and it shows how much you picked up
like on those simulators

what do you mean with this? why are you setting the scales to .5

because Nest_co said to because it puts the texts in the center. Earlier I set the offset to -50 - 1000, it worked but when I set it to a mobile device it doesn’t work properly. How do I fix this?

This is what you’ve gotta do, just use the scales instead and leave the offsets empty
Also I recommend setting the AnchorPoint of the label to (0.5,0.5)

2 Likes

So i mentioned earlier that you need to scale it properly, which means taking your offset and dividing it with the parents screen size
So if you want to move it to the left by 100pizels and the player screen size is 800pixels yout scale will be 100/800= 0.125
And your udim will be-
Udim2.new(0.125,0,0,0)

Yes, make sure your anchor point is set to 0.5

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.