How do I get mouse click position/tap position with context action service

So currently I want to use context action service to get the mouse click position and tap position, how do I do this.

You can look at the contextactionsrrvice documentation here for your answers ContextActionService | Roblox Creator Documentation

I already read over that I couldn’t find much for mouse posiiton.

Interesting, you can use UserInputType | Roblox Creator Documentation with context action services it’s said right there in the documentation.

Documemtatiom ContextActionService | Roblox Creator Documentation

Any number of Enum.KeyCode or Enum.UserInputType representing the inputs to bind to the action

So you can bind touch the CAS or mouse to the CAS function

Edit: NVM there actually is a method as CAS bind action returns the input object containing position and delta of a mouse wonder if it works for touch?

Perhaps this should work

1 Like

Yeah as the post above says it says you can on the documentation I sent

I can bind the actions pretty easily, but is there a way to get the position of the mouse or touch in world space from context action service or do I have to get it from the other services. Though the position you are talking about is screen position not the world position.

Basically I bind an action normally that detects mouse button click and touchpad touch. I just want to see the position in world space of that click or touch.

Yeah, you can just use UIS for that and this function to convert 2d screen position to 3D, previous post on this. TL;DR uses Camera | Roblox Creator Documentation or viewport point to ray.

local RAY_DISTANCE = 1000 -- default ray distance like mouse.Hit
local cam = workspace.CurrentCamera

function hitPosition(screenPosition,raycastParams, distance)
	local mousePos = screenPosition--modifying previous function a bit
	local viewportMouseRay = cam:ViewportPointToRay(mousePos.X, mousePos.Y)
	local rayCastResult = workspace:Raycast(viewportMouseRay.Origin, viewportMouseRay.Direction * (distance or RAY_DISTANCE), raycastParams)
	local hitPosition
	if rayCastResult then
		hitPosition =  rayCastResult.Position
	else
		hitPosition = viewportMouseRay.Origin+viewportMouseRay.Direction * (distance or RAY_DISTANCE)
	end
	return hitPosition
end
1 Like

Yea thanks this also works, also has more uses then mouse position.