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

How to get vector3 Value from mouse.Target?

So i'm trying to make a tree spawn at the place I click at and it works but it doesn't 100% work heres what happens http://i.gyazo.com/5fe1460494e84a39c526d51ac76106a1.png

The error http://gyazo.com/332065e0b8188fabf70df1ee0f3b0377

-- the code

local mouse = plugin:GetMouse()
mouse.Button1Down:connect(function()
local NewPart = Instance.new("Part")
NewPart.Anchored = true 
NewPart.Parent = game.Workspace
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 = Vector3.new(2, 3, 31.6) 
	local target = mouse.Target
	NewPart.Position = target -- where the error is happening
end)

2 comments

0

Try placing NewPart.Position=target.p You need to get the position of the mouse on line 14.

0

My only issue is, is it keeps saying that its userdata and can't be used but I have it like NewPart.Position = CFrame.new(target.CFrame) but then it throws a error saying vector expected? Help?

1 answer

✓ Accepted answer

Your Problem

mouse.Target will return a userdata(instance), so you need to index the Position property of target.


Code

local mouse = plugin:GetMouse()

mouse.Button1Down:connect(function()
	local NewPart = Instance.new("Part")
	NewPart.Anchored = true 
	NewPart.Parent = workspace
	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 = Vector3.new(2, 3, 31.6) 
	local target = mouse.Target
	NewPart.Position = target.Position
end)

2 comments

0

everything still just spawns in the same place http://i.gyazo.com/5f21e01d8e02b86214f41098f1b7dc4b.png

0

Edited.

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