Server-Sided R6 torso movement (Mouse)

I don’t know how to go about making a SERVER SIDED torso-follow mouse-movement. My game is a FPS game and I want all players to see where other players are facing in game. (right now, it looks like everyone is looking straight).

Help is appreciated! Thanks and happy Thanksgiving!

1 Like

You can use a LocalScript (under the character) to fire a line of code like this: (sourced from here)

local lookVector = game.Players.LocalPlayer.Character.CFrame.lookVector
local direction = math.deg(math.atan2(lookVector.x, -lookVector.z)

Then, you can fire a RemoteEvent from the LocalScript, carrying the direction information to a ModuleScript stored on the server (somewhere like ServerStorage or ReplicatedStorage).

Finally, you can make functions within that ModuleScript to update the information, and you can adjust the direction script (if one already exists) to grab from the module script. (Also, ensure that the LocalScript is constantly sending info to the ModuleScript so it regularly updates!)

1 Like

Omg thank you for replying! I’m not so great when it comes to scripting, unfortunately. would you mind giving me and example please? you could leave comments for me to fill in the things that are accustomed to my game* if you guys celebrate it, I hope your thanksgiving is going amazing!, if not then i hope you’re having a good day so far!!

1 Like

If you edit the position or the rotation of a part in the players character such as the torso even on the client it will replicate to the server and other players in the game anyway because the client side has network ownership of the torso.

To actually rotate it properly you need to change the properties of a Motor6D inside the torso which I believe for r6 is called waist or something like that (you can just check by expanding your character in the explorer in play mode).

The math required is slightly annoying but unavoidable unless you use a IK controller instead (less reliable more glitchy and may not replicate unless you spam remotes).

1 Like

Thanks for helping! I don’t mind if it’s a bit “laggy” (delayed or not as smooth – not updating fast) I just need help with the coding portion of all this. I’m not much of a coder, unfortunately.

Sure thing!

For example, in the LocalScript (under startercharacterscripts) you could do something like this:

local lookingModule = require(workspace.LookingModule) -- replace with module

while true do -- there may be an event that can handle this too if you want to replace it
  local lookVctr = game.Players.LocalPlayer.Character.CFrame.lookVector
  local direction = math.deg(math.atan2(lookVector.x, -lookVector.z)
  lookingModule[name] = direction
  task.wait(0.01) -- adjust as needed if you wish to keep this
end

ModuleScript:

local lookingModule = {}

return lookingModule

To implement into a script:

local lookingModule = require(workspace.lookingModule) -- replace with module pathway

for name,val in pairs(lookingModule) do -- will need something that will constantly repeat this event on the server (like a remote event)
 if name == selectedPlayer then -- assuming it cycles through all players
  cursor.Rotation = val -- assuming cursor is auto player-selected and a UI object
  -- continue code
 end
end

realized while editing this that you wouldnt need all of those remote events, sorry!

1 Like

I would give you the code just not sure how do to it without leaking the entire script thats in my game and besides mines R15 long story short its complex.

1 Like

You can also just go through the player list and get each character’s orientation directly from the server script like this (which is probably the better way to do it now that I think of it):

local Players = game:GetService("Players") -- ensures server has contact with Players

for _,plr in pairs(Players:GetChildren()) do -- again, needs something to constantly cycle this.
 local char = plr.Character
 local lookVctr = char.CFrame.lookVector
 local direction = math.deg(math.atan2(lookVctr.x, -lookVctr.z)
end

(also the last one had a naming error that’s fixed in this, and this requires only the server script)

1 Like

If you want to do it for using IKs its less reliable but heres a tutorial: https://www.youtube.com/watch?v=8fV-XOOj6O4&t=3067s

[NOTE]

Its in one of the last chapters in the video named “Character IKs”

1 Like

This goes into the Server Script correct? (Add onto the server script with this or replace server script code with this?

Yep, and that only needs the server script. Nothing else. Feel free to edit it as you need to fit your use case. (also you may want to add a quick task.wait [like 0.01 secs] so it wont repeat so fast and lag, and if you want you can replace it with events I think, which may be better performance wise)

move it on the client, every 0.1 seconds or so, fire a remote event to the server holding the rotation data and set it there

this is what I have so far…

Local Script:

Server Script:

Module Script:
Screenshot 2024-11-28 193313

you can delete the local script and module script, all you need is the server script part that i said in the latter reply

1 Like

so I only have the server script now… what else do I need to do?

That should be it, and if you want to print it, just do

print(direction)

you can view the output by going to view and selecting the output (2nd column, top one)

1 Like

But my torso isn’t even moving at all, am I missing something?

OH. I thought you were talking about putting little arrows on a minimap and getting the direction from the characters facing direction. sorry lmao its been a day :sob:

1 Like

oh :sob: nooo, I want my torso to move with the direction I am facing (my game is r6 characters and a first person shooter) I want this so players can see where other players are facing. Example: I can see a player looking UP at me on a rooftop, while they’re on the ground.

I see now. I presume this is head movement (and/or arm movement with aiming), correct?

1 Like