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

How can I position a part using mouse.hit?

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

✓ Accepted answer

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)

1 comment

0

a.CFrame = Position Also works to anyone looking at this question in the future.

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