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!
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!)
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!!
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).
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.
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!
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.
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)
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)
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
oh 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.