Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to get CFrame of a user's mouse on a surface?

I am developing a simple shooter game, but the only thing I am having difficulties with is getting the CFrame of the mouse on a surface.

Any assistance would be very helpful!

1 answer

You can use;

i think idk i don't use mouse stuff a lot

local Mouse = game.Players.LocalPlayer:GetMouse()
--Make sure you update this position each time you run it
local function update()
	if Mouse.Hit then
		local MousePosition = Mouse.Hit.Position
	end
end

--janky way to update it until you find a better way to run the code

while game:GetService("RunService").RenderStepped:wait() do
	update()
end

Let me know if this helps, you can also use this for more information;

https://developer.roblox.com/en-us/api-reference/property/Mouse/Hit#:~:text=The%20position%20of%20the%20Hit,an%20extended%20version%20of%20Mouse.&text=The%20orientation%20of%20the%20Hit,the%20direction%20of%20the%20Mouse.

This discussion is preserved as it was. New answers, comments, and votes are closed.