How whould i detect where a player clicked?

Let me get straight to the point, i want to make a script where it detects where the player clicked… i want to make like a thing where if i click somewhere it will explode…

1 Like

I think this article could help you:


Adding on to @ivandroide45’s answer, you can use Mouse | Roblox Creator Documentation if you want to specifically get a part the mouse is targeting. This will return nil if the mouse is not targeting a block (like the sky).

1 Like

In a localscript you could do this

local Player = game.Players.LocalPlayer; -- Get a player reference
local Mouse = Player:GetMouse(); -- Get a mouse reference

from here you can access Target or Hit


As @ivandroide45 and @TigerLeo77 Pointed out already.

In your case I recommend Hit.

  • The position of the Hit CFrame is calculated as the point of intersection between the mouse’s internal Ray (an extended version of Mouse.UnitRay ) and an object in 3D space (such as a part).

Mouse.Target works a little bit different which might require you to write more exception handlers

  • The object in 3D space the mouse is pointing to.

Roblox recommends phasing Mouse out of use in favor of UserInputService, and there are methods to get the equivalent of Mouse.Hit using Camera:ViewportPointToRay().

1 Like