Get the 2D position of a frame

Hey
im making a script where we can shoot balls but the ball position and direction will depend on where
the “cursor frame” is on the screen i dont know if its possible to get the 2D position of the red frame that’s why im asking it here

(Part of the script) :

local position = game.StarterGui.ScreenGui.Frame.Position

while true do wait()
	
	local ball = game.ReplicatedStorage:WaitForChild("Ball")
	local clone = ball:Clone()
	ball:Clone()
	clone.Parent = workspace
	clone.CFrame = part.CFrame * CFrame.new(0, -5, 0)
	
	local direction = position
	local forceMultipliter = 410 * ball:GetMass()
	
	clone:ApplyImpulse(direction * forceMultipliter)

Isn’t it just Frame.Position?

That’s what i’ve tried but im getting this error message

` ServerScriptService.Script:18: attempt to perform arithmetic (mul) on UDim2 and number`

Frame.Position is an UDim2, not a number lol.

Using Frame.Position will give you a UDim2 value (which contains 4 values), if you want a 2D position from the GUI you will have to grab just an x and y value from the frame. To easily do this you can just grab the Position’s X scale value (Frame.Position.X.Scale) and Y scale value. If you have any offset values set on your Gui, you’ll have to incorporate that to get your 2D x and y values.

1 Like

AbsolutePosition is the 2D position of the gui on the screen, with scale and offset applied.

2 Likes

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