Need help with script for FPS Game

So I have tried to make a script where the arms point towards the mouse, but I am trying to make it serversided.

But whenever I make it serversided its super laggy and unusable.

Heres the LocalScript


local player = game.Players.LocalPlayer
local character = player.Character
if not character or not character.Parent then
	character = player.CharacterAdded:wait()
end
local humanoid = character:WaitForChild("Humanoid")
local torso = character:WaitForChild("Torso")
local rightShoulder = torso:WaitForChild("Right Shoulder")
local leftShoulder = torso:WaitForChild("Left Shoulder")
local camera = game.Workspace.CurrentCamera

updateSpeed = 0.5/2

game:GetService("RunService").RenderStepped:Connect(function()
	local camCF = camera.CoordinateFrame
	script.camCF.Value = camCF
	--[[
	local camCF = camera.CoordinateFrame
	local distance = (character.Head.Position - camCF.p).magnitude
	if humanoid.Health ~= 0 then
		rightShoulder.C0 = rightShoulder.C0:lerp((camCF * CFrame.new(1, -1, 0)):toObjectSpace(torso.CFrame):inverse() * CFrame.Angles(0, math.pi/2, 0), updateSpeed)
		leftShoulder.C0 = leftShoulder.C0:lerp((camCF * CFrame.new(-1, -1, 0)):toObjectSpace(torso.CFrame):inverse() * CFrame.Angles(0, -math.pi/2, 0), updateSpeed)
	end
	--]]
	script.CamData:FireServer(camCF)
end)

And here is the ServerScript nested inside of said LocalScript

local player = script.Parent.Parent.Parent
local character = player.Character
if not character or not character.Parent then
	character = player.CharacterAdded:wait()
end

updateSpeed = 0.5/2
local humanoid = character:WaitForChild("Humanoid")
local torso = character:WaitForChild("Torso")
local rightShoulder = torso:WaitForChild("Right Shoulder")
local leftShoulder = torso:WaitForChild("Left Shoulder")


game:GetService("RunService").Stepped:Connect(function()
	if humanoid.Health ~= 0 then
		rightShoulder.C0 = rightShoulder.C0:lerp((script.Parent.camCF.Value * CFrame.new(1, -1, 0)):toObjectSpace(torso.CFrame):inverse() * CFrame.Angles(0, math.pi/2, 0), 0.5/2)
		leftShoulder.C0 = leftShoulder.C0:lerp((script.Parent.camCF.Value * CFrame.new(-1, -1, 0)):toObjectSpace(torso.CFrame):inverse() * CFrame.Angles(0, -math.pi/2, 0), 0.5/2)
	end
end)

script.Parent.CamData.OnServerEvent:Connect(function(p, data)
	script.Parent.camCF.Value = data
end)

And This is all inside of StarterGUI btw
image

I am trying to make it look like this btw
image
But just not laggy when you enter firstperson and just laggy in general

-- Insert this script into the StarterPlayer -> StarterPlayerScripts folder

-- Get references to player and character
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

-- Set up variables
local mouse = player:GetMouse()
local camera = workspace.CurrentCamera
local sensitivity = 0.1
local speed = 16

-- Function to handle player input
local function handleInput()
    local moveVector = Vector3.new(0, 0, 0)

    -- WASD movement
    if UserInputService:IsKeyDown(Enum.KeyCode.W) then
        moveVector = moveVector + Vector3.new(0, 0, -1)
    end
    if UserInputService:IsKeyDown(Enum.KeyCode.S) then
        moveVector = moveVector + Vector3.new(0, 0, 1)
    end
    if UserInputService:IsKeyDown(Enum.KeyCode.A) then
        moveVector = moveVector + Vector3.new(-1, 0, 0)
    end
    if UserInputService:IsKeyDown(Enum.KeyCode.D) then
        moveVector = moveVector + Vector3.new(1, 0, 0)
    end

    -- Normalize the vector and apply speed
    moveVector = moveVector.Unit * speed

    -- Rotate the moveVector based on camera orientation
    local camRotation = Vector2.new(camera.CFrame.LookVector.X, camera.CFrame.LookVector.Z).unit
    local moveDirection = camRotation:PointToWorldSpace(moveVector)

    -- Apply movement to character
    character:SetPrimaryPartCFrame(character:GetPrimaryPartCFrame() * CFrame.new(moveDirection * sensitivity))
end

-- Connect the function to the RenderStepped event
game:GetService("RunService").RenderStepped:Connect(handleInput)

Copy that script Go there you i have

1 Like

Have you tested this yourself? Because this doesn’t work…