I recently payed for a head movement script but just realised its one sided, i would like to know how i can make it so everyone can see it and not just the player.
![Capture d’écran 2024-05-11 125231](/secure-uploads/uploads/original/5X/2/b/5/4/2b54429d5cb092aaf38c5328ab5099a04e1f4eed.png)
I recently payed for a head movement script but just realised its one sided, i would like to know how i can make it so everyone can see it and not just the player.
One way of doing it is firing a remoteevent to the server, then you fire a remoteevent back but with :FireAllClients() this way, everyone will see the head movement, however it is still clientsided.
I see, I’m no scripter so I’m going to need some help. Would you like to assist me for this one?
Sorry, there is no way for me to properly format it on devforum, especially when the code you have shown is in images, I can not make edits to it myself unless you send a text version of it.
for sure, would you like it as a text instead?
Send it and I will try guiding you through making it work.
local Players = game:GetService(“Players”)
local RunService = game:GetService(“RunService”)
local player = Players.LocalPlayer
local camera = game.Workspace.CurrentCamera
local function findBoneRecursive(root, boneName)
for _, child in ipairs(root:GetChildren()) do
if child:IsA(“Bone”) and child.Name == boneName then
return child
else
local foundBone = findBoneRecursive(child, boneName)
if foundBone then
return foundBone
end
end
end
return nil
end
local function adjustNeckOrientation(character)
local policeReference = character:FindFirstChild(“RootPart”)
if not policeReference then
warn(“RootPart part not found”)
return
end
local neckBone = findBoneRecursive(policeReference, "ValveBiped.head")
if neckBone then
local cameraDirection = camera.CFrame.LookVector
local pitch = math.asin(cameraDirection.Y)
neckBone.Transform = CFrame.Angles(-0, -0, -pitch)
else
warn("Neck bone not found")
end
end
RunService.RenderStepped:Connect(function()
if player.Character then
adjustNeckOrientation(player.Character)
end
end)
does this work?
This will probably not be very good for performance, as you are firing a remote event constantly, but couldn’t think of a better way to do it.
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local player = Players.LocalPlayer
local camera = game.Workspace.CurrentCamera
local RemoteEvent = path.to.RemoteEvent
local function findBoneRecursive(root, boneName)
for _, child in ipairs(root:GetChildren()) do
if child:IsA("Bone") and child.Name == boneName then
return child
else
local foundBone = findBoneRecursive(child, boneName)
if foundBone then
return foundBone
end
end
end
return nil
end
local function adjustNeckOrientation(character)
local policeReference = character:FindFirstChild("RootPart")
if not policeReference then
warn("RootPart part not found")
return
end
local neckBone = findBoneRecursive(policeReference, "ValveBiped.head")
if neckBone then
local cameraDirection = camera.CFrame.LookVector
local pitch = math.asin(cameraDirection.Y)
neckBone.Transform = CFrame.Angles(-0, -0, -pitch)
else
warn("Neck bone not found")
end
end
RemoteEvent.OnClientEvent:Connect(function(Character)
adjustNeckOrientation(Character)
end)
RunService.RenderStepped:Connect(function()
if player.Character then
RemoteEvent:FireServer(player.Character)
end
end)
Then in a serverscript, you would want to run:
RemoteEvent.OnServerEvent:Connect(function(Player, Character)
RemoteEvent:FireAllClients(Character)
end)
Basically what it does is it fires from the players client constantly, to the server, and then the server replicates it to ALL clients (other players as well) Hope this works.
where should i put my remote event?
The only argument the server needs to figure out where it should place the character head is the current camera CFrame. So make a remote and pass that as the only argument(the player argument will be passed automatically, so you can use that to fetch the character on the server). Then run the same code on the server with the passed CFrame and it should replicate.
To make this show fast to the client(like how their character movement shows fast) you can also have the client script there so from their perspective the change happens incredibly fast.
Ideally what you can do is convert some of the functions you showed to a module and put in replicated storage, so you don’t need to have 2 scripts with the same code in them(better for organization).
Alternatively you can try a physics ownership related solution, although I don’t recommend it since it can create a vulnerability for exploiters to mess with.
ReplicatedStorage is just fine.
Characters
Alright, I suppose I just need to put the path to it in the script, correct?
The path just needs to match up, that’s the only important part, however I’d also recommend having it in ReplicatedStorage.
Alright so this is what i came up with.
I placed the RemoteEvent in RepliatedStoarge btw
Im not sure it worked, the other script is in ServerScriptService, probably not what you meant when you told me to put it in ServerScript.
You are writing this in a localscript, this needs to be in a normal script in ServerScriptService.
Yeah, still doesn’t work. Y’all have any more advice?
You maybe could just use a Server Script to begin with.
I don’t think it would cause any more lag than constantly sending a RemoteEvent to all players.
Just let the Server handle the head movements.
This is very stupid, because a remote event fired rapidly can extremely lag the game.
I would recommend a UnreliableRemoteEvent since it causes less lag when fired rapidly.