(UNSOLVED) How To Make Something Print When The Image Button Is Near The Frame

I am working on a game and was wondering how could I make the output print a word when the image button (The man moving) is near the white frame in the middle.
I tried

 if Imagebutton.Position == Frame.Position.Y then 


if ImageButton.Position == Frame.Position.X then

And nothing works any help would be appreciated.

if (Imagebutton.Position - Frame.Position).Magnitude < 3 then -- change 3 to the distance you want it to activate
--code here

I get the output

Magnitude is not a valid member of UDim2

I have no idea why it outputted this.

My bad, try

if (Imagebutton.AbsolutePosition - Frame.AbsolutePosition).Magnitude < 3 then
--code here

So, I tried putting that inside a loop and I put a print, yet whenever I got closed to it nothing happened. Is there a way I am supposed to do this without a loop?

You should try doing what @OrderDestroy said, But use RunService.RenderStepped to constantly check if the Magnitude is whatever we want.

local Character = "YourCharacterPathHere"
local Target = "YourTargetPathHere"

local RunService = game:GetService("RunService")
local RenderConnection = nil

RenderConnection = RunService.RenderStepped:Connect(function()
	-- Constantly check every RenderStepped Frame if the Magnitude
	-- Is near of whatever we want, In that case, 3.
	local Magnitude = (Character.AbsolutePosition - Target.AbsolutePosition).Magnitude

	-- Is the Magnitude less than 3? Yes? Disconnect the RenderConnection
	-- And do whatever we want!
	if Magnitude <= 3 then
		-- Do something here
		print("Magnitude is Less than 3!")
		RenderConnection = nil
1 Like

Hmm. I tried using this code, along with changing the target names and all, but nothing print’s when I get near the frame. This is confusing.

Change the magnitude to 200, I think the current one is too small.

Yup, now it works! Thanks for everybodys help.