Gui position detecting script won't work

I have a script that, if the gui element position reach -2 in Y axis, it should Reposition it at 0,0,0,0
Why the script won’t work?

while true do
	wait()
	script.Parent.Position -= UDim2.new(0, 0, 0.02, 0) -- works
	if script.Parent.Position.Y.Scale == -2 then -- problem
		script.Parent.Position = UDim2.new(0, 0, 0, 0)
		print("teleported to 0,0")
	end
end

Because you have it at 0.02 and not -2 i guess

The Position goes successfully down but it won’t stop at -2, it goes infinite (-3, -4, -5…)

script.Parent.Position -= UDim2.new(0, 0, 0.02, 0)

In this line i put -= that is like writing script.Parent.Position = script.Parent.Position - UDim2.new(0, 0, 0.02, 0)

1 Like

I solved it, apparently:
if script.Parent.Position.Y.Scale <= -2 then
Works

1 Like

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