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

How would I rotate this part so it's always pointing at mouse?

I have this code:

local Camera = game.Workspace.CurrentCamera

local part = script.Part


game:GetService('RunService').RenderStepped:connect(function()
	part.Parent = Camera
	part.CFrame = Camera.CoordinateFrame * CFrame.new(0,-2,-2)
end)

Which puts a part in the screen so it sticks blah blah, and I want to rotate it so it's pointing at the mouse, because as of the code it just is pointing horizontally off the screen. What would I do for that?

1 comment

1 answer

Your solution is really simple. Just use the CFrame constructor CFrame.new(Vector3 position, Vector3 lookAt).

--get the correct positioning
part.CFrame = Camera.CoordinateFrame * CFrame.new(0,-2,-2)

--rotate it, keeping the position we just set
part.CFrame = CFrame.new(part.Position, mouse.Hit.p)

4 comments

0

part is equal to script.Part*

0

Sorry. But my question remains, why would you have the part inside the script? If it's not in workspace, it won't be visible and if the script's in workspace it won't run.

0

actually the dude has the part inside of a camera??? also remember the script has to be a local script.

0

Yeah FilteringEnabled should be used for local parts instead of those hacky methods, they may not work.

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