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

How do i make a gun point to the camera?

The pistol moves when i move my mouse but not in the direction of the mouse.

 local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()

Mouse.Move:Connect(function()
script.Parent.Handle.Orientation += Vector3.new(0, Mouse.Hit.Y, 0)
end)

2 comments

0

You want it to point AT the camera? Or point where the camera is pointing?

0

point where the camera is pointing, sorry about the confusion

1 answer

You can have parts point to other parts by using CFrame.lookAt(). In this case the two arguments are position and the part you want to look at.

part1.CFrame = CFrame.lookAt(part1.Position, part2.Position)

In your case it would be:

handle.CFrame = CFrame.lookAt(handle.Position, mouse.Hit.p)

2 comments

0

it doesnt work, it flings me off the map.

0

Is the handle collidable? That might play a part.

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