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

How to get vector3 Value from mouse.Target?

Asked by
Prioxis 673 Moderation Voter
9 years ago

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)
0
Try placing `NewPart.Position=target.p` You need to get the position of the mouse on line `14`. woodengop 1134 — 9y
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? Prioxis 673 — 9y

1 answer

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

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)
0
everything still just spawns in the same place http://i.gyazo.com/5f21e01d8e02b86214f41098f1b7dc4b.png Prioxis 673 — 9y
0
Edited. Goulstem 8144 — 9y
Ad

Answer this question