Hello! Hope this message finds you well.
I am in the process of creating a Western Australian roleplay game, and scripting wise, I am having some difficulty. I am attempting to implement a system where the players body and head moves in regard to the turning of the players camera. Currently, this works perfectly, however it is not server sided. I have tried many avenues of ChatGPT, looking through forums, and believe me, this is my last resort option.
If someone could help me make this system work server sided, and possibly in addition have it disable in certain seats, that would be lovely. This is entirely optional about the seats, but if you have the time, it would be greatly appreciated. Reason being, I have a vehicle with a car driving animation, and when I enter the vehicle, it remembers the last camera angle they had it on before they entered, and locks the character into that position until they get out. In other seats, it works fine, just the driver seat - that could be from many things of course, but yea - would be nice.
Here is what I am trying to achieve to be server sided:
I have attached the current script below. It is a local script located under StarterPlayer → StarterCharacterScripts
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local Workspace = game.Workspace
local function onCharacterAdded(character)
local head = character:WaitForChild("Head")
local humanoid = character:WaitForChild("Humanoid")
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local rigType = humanoid.RigType.Value == 0
local torso = rigType and character:WaitForChild("Torso") or character:WaitForChild("UpperTorso")
local neck = rigType and torso:WaitForChild("Neck") or head:WaitForChild("Neck")
local waist = not rigType and torso:WaitForChild("Waist")
neck.MaxVelocity = 0.2
local currentCamera = Workspace.CurrentCamera
local u2 = false
local C0 = neck.C0
local CFrame_Angles = CFrame.Angles
local math_asin = math.asin
local u6 = 0.5 -- Reduced intensity
local u7 = not rigType and waist.C0
local u8 = 0.3 -- Reduced intensity
local math_atan = math.atan
RunService.RenderStepped:Connect(function()
local coordinateFrame = currentCamera.CoordinateFrame
if (rigType and character.Torso or character.UpperTorso) ~= nil and character.Head ~= nil then
local lookVector = torso.CFrame.lookVector
local p = head.CFrame.p
if (not (not rigType) and not (not neck) or neck and waist) and (currentCamera.CameraSubject:IsDescendantOf(character)) then
if not u2 then
local v15 = nil
local v16 = nil
v16 = (head.CFrame.p - coordinateFrame.p).magnitude
v15 = head.CFrame.Y - coordinateFrame.Y
if not rigType then
neck.C0 = neck.C0:lerp(C0 * CFrame_Angles(math_asin(v15 / v16) * 0.4, -(p - coordinateFrame.p).Unit:Cross(lookVector).Y * u6, 0), 0.1)
waist.C0 = waist.C0:lerp(u7 * CFrame_Angles(math_asin(v15 / v16) * 0.2, -(p - coordinateFrame.p).Unit:Cross(lookVector).Y * u8, 0), 0.1)
else
neck.C0 = neck.C0:lerp(C0 * CFrame_Angles(-(math_asin(v15 / v16) * 0.4), 0, -(p - coordinateFrame.p).Unit:Cross(lookVector).Y * u6), 0.1)
end
end
end
end
humanoid.AutoRotate = true
end)
end
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(onCharacterAdded)
end)
for _, player in Players:GetPlayers() do
if player.Character then
onCharacterAdded(player.Character)
end
end