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

How can I position a part using mouse.hit?

Asked by
Mystdar 352 Moderation Voter
8 years ago

I am trying position this part at the player's mouse when they lift the left mouse button.

player = game.Players.LocalPlayer
mouse = player:GetMouse()

mouse.Button1Up:connect(function()
    Position = mouse.Hit
    if game.Workspace:FindFirstChild(player.Name .."'s Point")~= nil then
        game.Workspace[player.Name .."'s Point"]:remove()
    end
    a = game.Lighting.Location:clone()
    a.Parent = workspace
    a.Name = player.Name .."'s Point"
    a.Position = Vector3.new(Position)
end)

It is currently being positioned at 0,0,0 when not being clicked at 0,0,0

1 answer

Log in to vote
1
Answered by 8 years ago

mouse.Hit is a CFrame position and Vector3 does not have a constructor that takes a CFrame value. Use the CFrame position.

player = game.Players.LocalPlayer
mouse = player:GetMouse()

mouse.Button1Up:connect(function()
    local Position = mouse.Hit
    if game.Workspace:FindFirstChild(player.Name .."'s Point")~= nil then
        game.Workspace[player.Name .."'s Point"]:remove()
    end
    a = game.Lighting.Location:clone()
    a.Parent = workspace
    a.Name = player.Name .."'s Point"
    a.Position = Position.p --CFrame position
end)
0
a.CFrame = Position Also works to anyone looking at this question in the future. Mystdar 352 — 8y
Ad

Answer this question