Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Directly clone a part from your cursor?

Asked by
j1011 0
9 years ago

How can this be done? Is this possible? Because i tried it and i can't seem to know how cursor works like i don't see any properties to do so. Thanks. I don't need the script by the way i just need to be enlighten

1 answer

Log in to vote
0
Answered by 9 years ago

It is possible to clone a part from your cursor. You need to get the position of the cursor and then clone the part, setting it's position to the position of the cursor.

Fortunately, there is a property called Hit in the Mouse which returns the CFrame of the mouse in the 3D space. which eliminates most of the hard work. You can convert this to a Vector3 by adding .p to the end of the Hit property.This basically converts the CFrame into a Vector3.

An example of what you could do is this (use a LocalScript and put it in StarterPack):

local player = game.Players.LocalPlayer --Gets the local player.
local mouse = player:GetMouse() --Gets the player's mouse
local part = game.Workspace.Part --You can change this to your part.
local db = false --Debounce variable, which is used to make the function only run once when the mouse is clicked.

mouse.Button1Down:connect(function() --Fires a function when the mouse is clicked.
    local hit = mouse.Hit.p --Get the position of the cursor in 3D space.
    local pClone = part:Clone()
    pClone.Parent = workspace --Global variable for game.Workspace.
    pClone.Position = hit --Moves the part to where the cursor is in 3D space.
end) --Closing parenthesis to wrap the function in the connection line.

I hope this helped you. If it did, be sure to accept my answer.

Ad

Answer this question