I'm wondering how it's possible to click somewhere and let's say that I'd like to spawn a brick on the coordinates of the clicked position. How could this be done?
mouse.Hit
mouse = game.Players.LocalPlayer:GetMouse() --this has to be a localscript! mouse.Button1Down:connect(function() -- button1down fires when the plsyer puts the mouse in a down state local part = Instance.new("Part") part.Position = mouse.Hit.p part.Parent = game.Workspace -- Hit is the position of where the mouse is pointing and .Hit is a CFrame, which is why there is a .p after it. end)
for more info, check the wiki for mouse
Since we're dealing with the mouse, we'll need to use the mouse class.
A property of mouse is mouse.Hit
. This is the position of where the mouse is pointing, which is what you want.
This returns a coordinate frame (CFrame). If you want the part to be exactly where the mouse was clicked use it. Although, if you want to use a Vector3 and make sure it's clear out the way, then use a property of CFrame itself, CFrame.p
, shown as mouse.Hit.p
.
Closed as Not Constructive by AmericanStripes
This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.
Why was this question closed?