Lock Player Orientation to Part

I have a flashlight, which i want to lock to the players orientation, but the flashlight only points to the bottom.

Here is my code:

local tool = script.Parent.Parent

local equipped = false

	equipped  = true
	local char = tool.Parent
	while equipped and wait() do
		tool.Grip = CFrame.new(Vector3.new(0,0,0), char.Head.Orientation)

	equipped = false

I might have misunderstood, but if you’re trying to change the direction of where the tool is pointing, why not just manually rotate the handle/grip in studio?

I want to rotate the Flashlight to the exact location the player is looking at.
So if the player looks up, the flashlight will follow the players orientation and when he looks back down, the flashlight will also look back down.
I hope you understand

Is this what you wanna achieve?

Yes, thank you. Do you have the code for that or can you tell me what i did wrong in my code?

Ah great, that’s called a ViewModel. It’s gonna be a bit messy if I have to explain it all over one reply, so I’ll link a video which explains how to set it all up. Best of luck!
How to make a ViewModel From Scratch - YouTube.

You’re welcome to reply with further questions if something isn’t working as you intend.

1 Like

Thank you! That worked, but whenever im in first person now, i automatically move forward. Do you have an idea why this is the case or even have an solution to this?

The viewmodel itself needs to have CanCollide set to false and anchored to true.

1 Like

Thanks, this works for me. Thank you for your help and patience!

1 Like

One last thing, no need to reply, but I forgot to mention which the video doesn’t show, you wanna add this code to the local script. And you wanna replace the “:SetPrimaryPartCFrame” with “:PivotTo”.

local Humanoid = Character:WaitForChild("Humanoid")

	ViewModel.Parent = nil

This deletes the viewmodel every time the player dies, and a new one is automatically created when player respawns.

1 Like

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