parent = script.Parent function onButton1Down(mouse) local model = parent.Wall:clone() model:MakeJoints()- creates the pieces model.Parent = game.Workspace-- places it in workspace model:MoveTo(mouse,mouse,mouse)--sets the location of mouse wait(10) workspace.Wall:Destroy() end --- I am confused what to do from here
--Okay this is the revised script parent = script.Parent local Player = game.Players.LocalPlayer local mouse = Player:GetMouse() local wall = parent.Wall:clone() mouse.Button1Down:connect(function() wall:MakeJoints() wall.Parent = game.Workspace wall:MoveTo(mouse,0,mouse) wait(10) wall:Destroy() print("works") end) ---and still nothing
This should work for you:
[LocalScript]
local model = workspace.Model -- this should be the model you want to move local camera = workspace.CurrentCamera game:GetService("UserInputService").InputBegan:connect(function(inputObject) if (inputObject.UserInputType ~= Enum.UserInputType.MouseButton1) then return end local mousePosition = inputObject.Position local mouseRayUnit = camera:ScreenPointToRay(mousePosition.X, mousePosition.Y) local mouseRay = Ray.new(mouseRayUnit.Origin, mouseRayUnit.Direction * 1000) local _, mouseTarget, _ = workspace:FindPartOnRayWithIgnoreList(mouseRay, {model}) model:MoveTo(mouseTarget) end)
Let's dive into what this is doing.
First, we have this line:
local mouseRayUnit = camera:ScreenPointToRay(mousePosition.X, mousePosition.Y)
What that line does is take the position of the mouse on the screen and convert it into a unit Ray. (If you don't know what a ray is, you'll have to do some research.)
Next, we have this:
local mouseRay = Ray.new(mouseRayUnit.Origin, mouseRayUnit.Direction * 1000)
What that does is take the unit ray and extend it to be 1000 studs long. This code means that whatever is being placed can be, at maximum, 1000 studs away from the camera's position.
Finally, we have this:
local _, mouseTarget, _ = workspace:FindPartOnRayWithIgnoreList(mouseRay, {model})
What this does is attempt to find the first part that intersects with the ray. We extract the position of the part that was found and use that to position the model.
If you're using FilteringEnabled, you'll have to make some tweaks for this to show up for other clients.
You'll also have to add in the rest of the code that you need.
I hope this helps! Good luck.
--- The best answer to this question is to actually make the part through coding --- the above answer is incorrect in my eyes, because it fails to function when testing in roblox studios --- Also, I love to use hopperbins.