I tried to check the frame position but it’s not working.
Local Script:
if Frame.Position.X.Scale == 0.5 and Frame.Position.Y.Scale == -0.7 then
print("Open")
else
print("Close")
end
The frame position
I tried to check the frame position but it’s not working.
Local Script:
if Frame.Position.X.Scale == 0.5 and Frame.Position.Y.Scale == -0.7 then
print("Open")
else
print("Close")
end
The frame position
I don’t understand entirely, why are you using .Scale there if you’re trying to check the position? (Sorry I am not the best with GUI properties)
so I can fit the UI on all devices.
I see, but this code is checking the whether the scale is equal to 0.5 or -0.7. Shouldn’t you just be checking the size and then fitting it to all devices?
why would I do that I just want to check the position of the frame.
Full Script:
local function TweenFrames(Frame)
local FrameTweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Elastic, Enum.EasingDirection.InOut)
print("Run")
if Frame.Position.X.Scale == 0.5 and Frame.Position.Y.Scale == -0.7 then
print(Frame.Position)
local FrameTween = TweenService:Create(Frame, FrameTweenInfo, {Position = UDim2.new(0.5, 0, 0.5, 0)})
FrameTween:Play()
else
local FrameTween = TweenService:Create(Frame, FrameTweenInfo, {Position = UDim2.new(0.5, 0, -0.7, 0)})
FrameTween:Play()
end
end
Sorry I meant position. Try something like this:
if Frame.Position.X == 0.5 and Frame.Position.Y == -0.7 then
-- the rest
The code doesn’t work. It only prints Run.
Nothing appears to be wrong here, if you haven’t already done so, try adding a print statement under if and else to see what happens and if that doesn’t do anything, I would recommend restarting Studio.
If I am not mistaken, you cant compare the X and Y values directly like that.
This won’t work due to floating point precision errors, machines represent base 10 (decimal) numbers using base 2 (binary), consequently certain numbers can’t be represented exactly, i.e; the square root of 2.
To resolve this you could convert the numbers into integers and compare those instead, as integers are not subject to these precision errors.
if math.round(Frame.Position.X.Scale * 10) == 5 then
--Do code.
end
Thank You so much for making this. Been trying to figure out how to make if position functions for a while now.