Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I create a part at my mouse position using a plugin?

So i'm creating a plugin that will make a tree (part with a mesh) at wherever I click But I don't really know how to accomplish this it's been awhile since i've been on roblox studio/used lua

so far heres my script

local version = "1.0.0" -- plugin stuff
local plugin = PluginManager():CreatePlugin()
local toolbar = plugin:CreateToolbar("Hello World Plugin")
local button = toolbar:CreateButton(
	"Tree Creator", -- The text next to the icon. Leave this blank if the icon is sufficient.
	"Click to make tree!", -- hover text
	""
)
local On = false
local player
local mouse = player.GetMouse()
function OB1D(mousee) -- create tree function \/\/\/\/\/
local HTarget = mouse.Target 
local HPosition = mouse.Hit.p 
local NewPart = Instance.new("Part")
NewPart.Anchored = true 
NewPart.Parent = game.Workspace
NewPart.Position = HPosition
local Mesh = Instance.new("SpecialMesh", NewPart)
Mesh.MeshId = "http://www.roblox.com/asset/?id=150251147"
Mesh.Scale = Vector3.new(3.1, 3.1, 3.1)
Mesh.TextureId = "http://www.roblox.com/asset/?id=150251554"
NewPart.Size = CFrame.new(2, 3, 31.6) 
end

button.Click:connect(function() -- click the plugin button
On = true
end)

if On == true then
mouse.Button1Down:connect(function(create) -- where I need help 
	
end)
end

1 answer

✓ Accepted answer

Just put this under the MouseButton1Down function.

local part = Instance.new("Part",game.Workspace)
part.Position = mouse.Hit

If it works please vote up and accept answer!

This discussion is preserved as it was. New answers, comments, and votes are closed.