UDim2.new + Variable = doesn't work

Hello, what I want: a variable should replace a Udin2 value.
What happens. The value in question is set to 0 at the position although the variable is something completely different.
Output:

Code:

Code

abstand = 212

if foundn <= 5 then
					local y = tonumber((abstand*foundn-212)/1000)
					print(y)
					v.Position = UDim2.new(0,(abstand*foundn-212)/1000,0.212,0)
					print(v.Position)
end

Output:

Output

20:03:31.736 1 - Edit - #
20:03:31.736 0 - Edit - #…
20:03:31.736 {0, 0}, {0.211999997, 0} - Edit -
20:03:31.736 2 - Edit -
20:03:31.736 0.212 - Edit -
20:03:31.736 {0, 0}, {0.211999997, 0} - Edit -
20:03:31.736 3 - Edit -
20:03:31.736 0.424 - Edit -
20:03:31.737 {0, 0}, {0.211999997, 0} - Edit -
20:03:31.737 4 - Edit -
20:03:31.737 0.636 - Edit -
20:03:31.737 {0, 0}, {0.211999997, 0}

I have tried so much, nothing has worked out
Thanks in advance!

The reason it doesn’t work is:
If you try to put floating numbers (0.124, 5.856 etc.) into the offset section

Udim2 has 4 inputs: ScaleX, OffsetX, ScaleY, OffsetY

they will round down to the nearest integer. (0.124 becomes 0, 5.856 becomes 5)

So you should put the (abstand*foundn-212)/1000 thing into the ScaleX section instead of OffsetX section and the new line should look like this:

v.Position = UDim2.new((abstand*foundn-212)/1000,0,0.212,0)
1 Like

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