Pretty self explanatory. I would like to get the mouse position. Any help will be apriciated thanks in advance
✓ ANSWER ACCEPTED
is there any way to get the mouse position? if so then how?
1 answer
✓ Accepted answer
You can do that by getting the mouse's Hit.p property.
In the code below hitPosition is the 3D position in the workspace that the mouse is hitting.
hitPosition is a vector3 value in the workspace.
Make sure you put this in a localscript
mouse = game.Players.LocalPlayer:GetMouse()
hitPosition = mouse.Hit.p
print(hitPosition)
Here's an example that moves a brick to the position of the mouse: We need to put the part in the mouse's target filter otherwise the mouse will try to put the brick at the position of the part over and over again and i'll look glitchy.
--create a new part
part = Instance.new("Part", game.Workspace)
part.Size = Vector3.new(1,1,1)
part.Anchored = true
mouse = game.Players.LocalPlayer:GetMouse()
mouse.TargetFilter = part -- add the part to the target filter
--get current hitposition update position of part to be hitPosition
while(wait())do
local hitPosition = mouse.Hit.p
part.Position = (hitPosition)
print("Position: ",hitPosition)
end
This discussion is preserved as it was. New answers, comments, and votes are closed.
