hi guys i was trying to do a skinned mesh character move his head with camera.cframe but what did i do wrong in the script?
server script
local RS = game:GetService("ReplicatedStorage")
game.Players.PlayerAdded:Connect(function()
RS.HeadRotation.OnServerEvent:Connect(function(plr, CameraCFrame)
for i,otherplr in pairs(game.Players:GetChildren()) do
if otherplr ~= plr then
RS.HeadRotation:FireAllClients(otherplr,plr, CameraCFrame)
end
end
end)
end)
localscript
RunService.RenderStepped:Connect(function()
wait(0.5)
game.ReplicatedStorage.HeadRotation:FireServer(Camera.CFrame)
end)
game.ReplicatedStorage.HeadRotation.OnClientEvent:Connect(function(otherplr,headcframe)
local head = otherplr.Character.RootPart.Hips.Spine.Spine1.Spine2.Neck.Head
if head then
print(otherplr)
TweenService:Create(head,TweenInfo.new(0.5, Enum.EasingStyle.Sine,Enum.EasingDirection.InOut),{TransformedWorldCFrame = headcframe}):Play()
end
end)
it says its read only how can i edit the transformedworldcframe of a bone?
TransformedWorldCFrame is read-only. You cannot set it.
Bones are only moved through .Transform.
Fix: serverscript: local RS = game.ReplicatedStorage
local evt = RS.HeadRotation
game.Players.PlayerAdded:Connect(function(plr)
evt.OnServerEvent:Connect(function(sender, cf)
for _, other in ipairs(game.Players:GetPlayers()) do
if other ~= sender then
evt:FireClient(other, sender, cf)
end
end
end)
end)
localscript: local RS = game.ReplicatedStorage
local evt = RS.HeadRotation
local cam = workspace.CurrentCamera
local RunService = game:GetService(“RunService”)
evt.OnClientEvent:Connect(function(otherplr, cf)
local head = otherplr.Character.RootPart.Hips.Spine.Spine1.Spine2.Neck.Head
if head then
head.Transform = head.Transform:Lerp(cf - cf.Position, 0.2)
end
end)
game.ReplicatedStorage.HeadRotation.OnClientEvent:Connect(function(otherplr,headcframe)
RunService.PreRender:Connect(function()
local char = otherplr.Character
local head = char.RootPart.Hips.Spine.Spine1.Spine2.Neck.Head
if head then
head.Transform = head.TransformedCFrame:Lerp(headcframe - headcframe.Position, 0.2)
end
end)
end)
it doesnt rotate but it just makes the head kindly rotated to the front
local cache = {}
--# OnClient Event
RunService.RenderStepped:Connect(function()
game.ReplicatedStorage.HeadRotation:FireServer(Camera.CFrame)
wait(0.5)
end)
game.ReplicatedStorage.HeadRotation.OnClientEvent:Connect(function(otherplr,headcframe)
cache[otherplr] = headcframe
RunService.PreRender:Connect(function()
for player, cframe in pairs(cache) do
local char = otherplr.Character
local head = char.RootPart.Hips.Spine.Spine1.Spine2.Neck.Head
if head then
head.Transform = head.Transform:Lerp(headcframe - headcframe.Position, 0.2)
end
end
end)
end)
game.Players.PlayerRemoving:Connect(function()
if cache[Player] then
cache[Player] = nil
end
end)
You should move the RunService connection out of the HeadRotation event. Also waiting in a connection doesn’t prevent it from firing for the wait duration so you should make it a loop for now.
For example:
task.spawn(function()
while task.wait(0.5) do
--# :FireServer here.
end
end
Is there a way you could show me a video or photo of how it currently looks?
local cache = {}
--# OnClient Event
task.spawn(function()
while task.wait(0.5) do
RunService.RenderStepped:Connect(function()
game.ReplicatedStorage.HeadRotation:FireServer(Camera.CFrame)
end)
end
end)
game.ReplicatedStorage.HeadRotation.OnClientEvent:Connect(function(otherplr,headcframe)
cache[otherplr] = headcframe
RunService.PreRender:Connect(function()
for player, cframe in pairs(cache) do
local char = otherplr.Character
local head = char.RootPart.Hips.Spine.Spine1.Spine2.Neck.Head
if head then
head.Transform = head.Transform:Lerp(headcframe - headcframe.Position, 0.2)
end
end
end)
end)
game.Players.PlayerRemoving:Connect(function()
if cache[Player] then
cache[Player] = nil
end
end)
local cache = {}
--# OnClient Event
task.spawn(function()
while task.wait(0.5) do
game.ReplicatedStorage.HeadRotation:FireServer(Camera.CFrame)
end
end)
game.ReplicatedStorage.HeadRotation.OnClientEvent:Connect(function(otherplr,headcframe)
cache[otherplr] = headcframe
end)
RunService.PreRender:Connect(function()
for player, cframe in pairs(cache) do
local char = otherplr.Character
local head = char.RootPart.Hips.Spine.Spine1.Spine2.Neck.Head
if head then
head.Transform = head.Transform:Lerp(headcframe - headcframe.Position, 0.2)
end
end
end)
game.Players.PlayerRemoving:Connect(function()
if cache[Player] then
cache[Player] = nil
end
end)
This is what I mean. Should have probably worded it different.
Ah. In the RunService.PreRender the player variable is called player and the cframe variable is called cframe. Not otherplr and headcframe. You can change those.