Rotating a tool while it's equipped

Hey! I haven’t coded in many years and even so I was a beginner, so let’s say I’m a complete newbie. Here’s what’s up:

The camera mode is locked to first person at all times. I have a flashlight tool which I give the player. The flashlight, of course, rotates towards the horizontal direction the player is facing at all times BUT it does not rotate vertically, as in up and down where the first person camera is looking towards.
Whenever I try to do this, the player starts rapidly being thrown about in a jittery motion relative to where I’m pointing the mouse (but the rotating thing works). Here is my code (I’m a beginner, so the CFrame stuff I really don’t understand, it was autofilled by Roblox, haha):

while tool.Parent == plr.Character do
	local lookVector = camera.CFrame.LookVector
	handle.CFrame = CFrame.new(handle.Position, handle.Position + lookVector)
	task.wait(0.1)
end

Please help if you can, I’m so stuck on this, I’ve really tried everything. Thank you!

Edit: Here’s what’s happening with my code:
Untitled video - Made with Clipchamp

I’m guessing the solution here is to change the Grip property instead

When you equip a tool it is always locked on to the player’s hand using that Grip property, so changing the CFrame would either move the player to match the rotation or just snap the tool back in place

Alternatively you might be able to make the handle an invisible part and add Motor6Ds which weld the actual model of it to the handle, so you can change C1/C0 without updating the handle’s CFrame

I may be doing something wrong but this didn’t work (it seems to do nothing at all, actually) so I’ll try the other thing:

while tool.Parent == plr.Character do
	local lookVector = camera.CFrame.LookVector
	tool.Grip = CFrame.new(tool.Grip, tool.Grip + lookVector)
	task.wait(0.1)
end

Maybe try CFrame.lookAlong() with only the lookVector as the second param, like

CFrame.lookAlong(grip,lookVector)

I gave up with trying to rotate the handle or the actual ‘tool’ class, and instead I did as you suggested and made the handle invisible and welded the actual tool to it. Thank you!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.