How would I make this localscript serversided?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

  2. What is the issue? Include screenshots / videos if possible!

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

--- Services ---
local Players = game:GetService("Players");
local RunService = game:GetService("RunService");
local Workspace = game:GetService("Workspace");

wait();

--- Declarations ---
local Player = Players.LocalPlayer;
local Character = Player.Character or Player.CharacterAdded:Wait();

local Camera = Workspace.CurrentCamera;


--- Character ---
local RightUpperArm = Character:WaitForChild("RightUpperArm");
local RightShoulder = RightUpperArm:WaitForChild("RightShoulder");
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart");
local EE = Character:WaitForChild("UpperTorso");
local Waist = EE:WaitForChild("Waist");
local Head = Character:WaitForChild("Head");
local Neck = Head:WaitForChild("Neck");

local camLimit = RunService.Stepped:Connect(function()
	local CameraCFrame = HumanoidRootPart.CFrame:ToObjectSpace(Camera.CFrame)
	local x, y, z = CameraCFrame:ToOrientation()
	local a = Camera.CFrame.Position.X
	local b = Camera.CFrame.Position.Y
	local c = Camera.CFrame.Position.Z

	local xlimit = math.rad(math.clamp(math.deg(x),-75,75))
	local ylimit = math.rad(math.clamp(math.deg(y),-75,75))
	local zlimit = math.rad(math.clamp(math.deg(z),-75,75))
	Camera.CFrame = HumanoidRootPart.CFrame:ToWorldSpace(CFrame.new(a,b,c) * CFrame.fromOrientation(xlimit,ylimit,zlimit))
end)


--- Execution ---
RunService.Stepped:Connect(function()
	local cameraCFrame = Camera.CFrame;

	-- Get the direction by taking the forward vector of the camera
	local direction = cameraCFrame.LookVector * 5000;

	-- Get the rotation offset
	local rootCFrame = HumanoidRootPart.CFrame;
	local rotationOffset = (rootCFrame - rootCFrame.Position):Inverse();

	-- Calculate the new transforms
	RightShoulder.Transform = rotationOffset * CFrame.new(Vector3.new(0, 0, 0), direction) * CFrame.Angles(math.pi / 2, 0, 0);
	Waist.Transform = rotationOffset * CFrame.new(Vector3.new(0, 0, 0), direction) * CFrame.Angles(math.pi / 20, 0, 0);
	Neck.Transform = rotationOffset * CFrame.new(Vector3.new(0, 0, 0), direction) * CFrame.Angles(math.pi / 25, 0, 0);
	

end)



local bodyGyro = Instance.new("BodyGyro")
bodyGyro.Parent = HumanoidRootPart
bodyGyro.MaxTorque = Vector3.new(0, 4000, 0) 

local delay = 0.36

while true do
	wait()


	wait(delay)

	local targetPosition = HumanoidRootPart.Position + Vector3.new(Camera.CFrame.LookVector.X, 0, Camera.CFrame.LookVector.Z)
	local targetCFrame = CFrame.new(HumanoidRootPart.Position, targetPosition)

	local alpha = 0.05 

	HumanoidRootPart.CFrame = HumanoidRootPart.CFrame:lerp(targetCFrame, alpha)


	-- Adjust character orientation using BodyGyro
	local lookDirection = (targetPosition - HumanoidRootPart.Position).unit
	bodyGyro.CFrame = CFrame.new(HumanoidRootPart.Position, HumanoidRootPart.Position + lookDirection)
end


Please do not ask people to write entire scripts or design entire systems for you. If you can't answer the three questions above, you should probably pick a different category.

copy paste all code in server script, find player by PlayerAdded, change RunService.Stepped to RunService.Heartbeat

while true do
wait()

to
while wait() do

1 Like

This is not possible (nor is it necessary) to make this script server-sided. There is no such thing as a “CurrentCamera” for the server – this is only a local thing.

What are you trying to accomplish with this script? Why do you need it to be server-sided?

If you want this to replicate to the server, then you’ll have to periodically a remote event and pass the local player’s CurrentCamera LookVector as a parameter, then change the positioning of the player’s limbs in a server script.

There are a few problems with this, however.

1. There is a limit to how many remote events you can fire every second. Firing too many in rapid succession will lead to dropped requests.

2. It will not replicate perfectly because of the inherent delay in communicating between client and server. This will cause it to look bad/choppy/slow for the local player.

1 Like

What im trying to do is make the players arm/body follow the camera smoothly if making the script serversided is impossible then how would i go about doing this on the serverside?

You can just FireServre then FireAllClients with the appropriate cframes for the character.

1 Like