How to make the player's waist move to the camera direction!

How to: use waist movement in roblox!

Lets just get straight to it. First, make a localscript in startercharacterscripts.

In that script, I recommend putting wait(4) or another method just to make sure the player’s model has loaded in completely by the time the script is executed.

Now, to the scripting part.

First of all, make a RenderStepped loop.

game:GetService("RunService").RenderStepped:Connect(function()

end)

Good. Before the RenderStepped function is called, make a variable called waist that gets the players Waist.

waist = script.Parent:FindFirstChild("Waist",true)

Now in the RenderStepped function, do this:

game:GetService("RunService").RenderStepped:Connect(function()
if waist then
local camDirection = script.Parent:FindFirstChild("HumanoidRootPart").CFrame:ToObjectSpace(workspace.CurrentCamera.CFrame).LookVector

waist.C0 = CFrame.new(0,waist.C0.Y,0) * CFrame.Angles(0,-camDirection.X,0) * CFrame.Angles(camDirection.Y,0,0)
end
end)

There ya go! A finished waist movement system in Roblox!

If you want to have head movement added onto that, add a coroutine to the script and have it run this (I am not explaining how to do it as it is off-topic):

local neckTurn = coroutine.create(function()
		game:GetService("RunService").RenderStepped:Connect(function()
			wait()
			if neck then
				local camDirection = hrp.CFrame:ToObjectSpace(workspace.CurrentCamera.CFrame).LookVector

				neck.C0 = CFrame.new(0,neck.C0.Y,0) * CFrame.Angles(0,-camDirection.X,0) * CFrame.Angles(camDirection.Y,0,0)
			end
		end)
	end)

and make a variable called neck:

neck = script.Parent:FindFirstChild("Neck",true)

If you notice any mistakes or the script not working, please let me know!

Thank you

10 Likes

Why the wait on the Render stepped connection?

Players can take some time to load their body parts, as the script is Local.

I’ll drop an improved version of the code for you later.

  1. So you aren’t supposed to use wait anymore use task.wait instead
  2. and you also wouldn’t wait for the character to load inside of the callback
  3. once the character is loaded then connect the event
  4. not sure why you are using a coroutine for it as connecting an event wouldn’t halt the thread
  5. you also wouldn’t get the camera every frame, lack of proper scope usage
  6. lack of variable usage

the CFrame is probably fine? that’s the only thing I don’t know of

3 Likes

Just check if what you need is loaded or not with :FindFirstChild.

Having a wait makes using RenderStepped useless.

I recommend you look into colbert’s topic about :WaitForChild, you can find better understanding from there on what exactly to do.

1 Like

Oh yeah! Sorry about that. I actually didn’t realize how badly it was written! But thanks for the feedback!

Improved Version

Note:

  • This is Client side only, meaning the neck movement will not replicate
  • you’ll need to use a RemoteEvent to replicate neck movement
1 Like