I have been working on a game lately that requires a lot of npc to be manipulated. I have come across a way to make it super optimized by only having a humanoidRootPart with the humanoid on the server side and the rest of the body to be only replicated on the client. In the code bellow, ‘body’ refers to an objectValue that defines a model in the replicatedStorage to be used as the monster’s body.
workspace.Entities.ChildAdded:Connect(function(monster)
local body = monster:WaitForChild("Body")
local clone = body.Value:Clone()
local weld = Instance.new("WeldConstraint")
local hrp = monster:WaitForChild("HumanoidRootPart")
hrp.Transparency = 1
hrp.CanCollide = false
hrp.CanQuery = false
clone.Parent = monster
weld.Parent = hrp
clone:PivotTo(hrp.CFrame)
weld.Part0 = hrp
weld.Part1 = clone.PrimaryPart
for i,v in pairs(clone:GetChildren()) do
v.Parent = monster
if v.Name == "HumanoidRootPart" then
v:Destroy()
end
end
clone:Destroy()
animationManager(monster)
end)
Problem is, it has a lot of problems and isnt really reliable with animations. Does anyone have a quicker way in mind that I could achieve this? Here are some pictures for better understanding
SERVER SIDE
CLIENT SIDE