So for a script I am programming I need to know the position of a UI. For some reason the code I am running does not seem to work. I am unsure why, does anyone have any ideas how I can fix/do this?
Make sure that the distance is accurate and the position is also accurate.
You can also try absolute position
To check if the Positon and distance are accurate try this
if Distance < 12.5 and plr.PlayerGui.ScreenGui[“Register Start Screen”].Position == UDim2.new(0.288,0,0.235,0) then
print(“both statements are true, this means that the code should run”)
-—do whatever else here
else
print(Distance)
print(plr.PlayerGui.ScreenGui[“Register Start Screen”].Position)
—see if the values are true or false compared to the if statements
end
Most likely, but what if it was an error in position or distance? that code was just meant to check if the if statements were true (because the code they provided should work)
After trying to replicate the problem I think I found the issue.
Whenever you try to print the position, it is not the exact position. (I believe this is a floating point error.)
Try to do this
local function normalizeUDim2(udim2)
return UDim2.new(
math.round(udim2.X.Scale * 1000) / 1000,
udim2.X.Offset,
math.round(udim2.Y.Scale * 1000) / 1000,
udim2.Y.Offset
)
end
local Position = normalizeUDim2(yourPosition)
if Position == UDim2.new(0.288,0,0.235,0 then
—code here
end
hmm. Another way I tried (which probably which won’t work in most cases) is that I printed the position of the GUI right before the if statements ran. Then I changed the if statements to the printed position.