Any way to make the gui act like Mouse.Hit.P?

Im trying to make a little dot image gui act like mouse.Hit.P idk exactly how to do it so im wondering if anyone else does

bassically where ever the dots position is it will act as if the dot was the mouse

Sorry, I’m not sure what you’re asking for. Are you trying to find the position of the player’s mouse in 3D coordinates?

yes thats exactly what im trying to do, i couldnt find the exact words for it, well not exactly but im trying to find the position of a gui in the 3d cordinates

You can use a raycast.

Code:

local currentCamera = workspace.CurrentCamera
local myDotGui = script.Parent.Whatever

local function Get3DPosition()
	local absolutePosition = myDotGui.AbsolutePosition

	local unitRay = currentCamera:ScreenPointToRay(absolutePosition.X, absolutePosition.Y)
	local raycastResult = workspace:Raycast(unitRay.Origin, unitRay.Direction * 100)
	
	return raycastResult.Position
end

print(Get3DPosition())
1 Like

tysm, im still new to gui scripting and stuff(i avoid it most of the time and stick to making abilities and stuff) really appreciate it bro

1 Like

Yeah don’t worry, this is one of the more advanced concepts. If you need any other help, feel free to ask.

1 Like

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