#I need help with server side head turning

1 messages · Page 1 of 1 (latest)

untold temple
#

So far I managed to get Head Turning to work, however I need some assistance in making it work server side

bitter lava
#

fire a event and send the cframe from client to server

#

then apply the tween from the server to the neck

untold temple
#

Here's the current script for serverscriptservice, Idk what's wrong with it.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local event = ReplicatedStorage:WaitForChild("Head_Movement_Event")

event.OnServerEvent:Connect(function(player, data)
local character = player.Character
if not character then return end

for i = 1, #data, 2 do
    local boneName = data[i]
    local transform = data[i + 1]

    local bone = character:FindFirstChild(boneName, true)
    if bone and typeof(transform) == "CFrame" then
        bone.Transform = transform
    end
end

end)

bitter lava
#

only where its firing the event

untold temple
# bitter lava send the client

local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local player = Players.LocalPlayer
local camera = workspace.CurrentCamera
local character = player.Character or player.CharacterAdded:Wait()
local root = character:WaitForChild("RootPart")

local event = ReplicatedStorage:WaitForChild("Head_Movement_Event")

-- Bones (neck to head)
local bones = {
character:FindFirstChild("Bone.004", true),
character:FindFirstChild("Bone.005", true),
character:FindFirstChild("Bone.006", true),
character:FindFirstChild("Bone.007", true)
}

-- Store original transforms for reset
local originalTransforms = {}
for i, bone in bones do
if bone then
originalTransforms[i] = bone.Transform
end
end

-- Freeze state check
local function isFrozen()
local statusFolder = character:FindFirstChild("DCS_No_Change")
if not statusFolder then return false end
statusFolder = statusFolder:FindFirstChild("Status_Values")
if not statusFolder then return false end

local sleeping = statusFolder:FindFirstChild("IsSleeping")
local tranqed = statusFolder:FindFirstChild("IsTranqed")
local roaring = statusFolder:FindFirstChild("IsRoaring")

return (sleeping and sleeping.Value) or
    (tranqed and tranqed.Value) or
    (roaring and roaring.Value)

end

-- Rotation calculation (returns offset CFrame)
local function getOffsetTransform(xClamp, yClamp)
local dir = root.CFrame:ToObjectSpace(camera.CFrame).LookVector / 2
local yaw = math.clamp(math.asin(dir.X), -xClamp, xClamp)
local pitch = math.clamp(-math.asin(dir.Y), -yClamp, yClamp)
return CFrame.Angles(pitch, 0, yaw)
end

-- Tween reset to animation (removes offset)
local function tweenBackToAnimation()
for i, bone in bones do
if bone then
-- Tween back to current animation transform (removes offset)
TweenService:Create(bone, TweenInfo.new(0.5), {Transform = bone.Transform}):Play()
end
end
end

-- Main tracking loop
RunService.RenderStepped:Connect(function()
if isFrozen() then
tweenBackToAnimation()
return
end

for i, bone in bones do
    if bone then
        local offset = getOffsetTransform(math.pi / (5 + i), math.pi / (5 + i))
        -- Layer the offset on top of the animation's transform
        bone.Transform = bone.Transform * offset
    end
end

end)

-- Server sync loop
while true do
task.wait(0.3)
if isFrozen() then continue end

local data = {}
for _, bone in bones do
    if bone then
        table.insert(data, bone.Name)
        table.insert(data, bone.Transform)
    end
end
event:FireServer(data)

end

bitter lava
#

inside renderstepped

untold temple
#

Forgive me if I'm struggling with this, I'm currently using chatgpt to help with my scripts

bitter lava
untold temple
#

Welp, didn't work

bitter lava
untold temple
bitter lava
#

like this

untold temple
#

But still, its not working