Better way to use Humanoids

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
image
image

CLIENT SIDE
image

1 Like

EDIT: The body is now well attached to the box, now I only need to find a way to animate it properly since I am unable to do it trough local script. I just copied an animate script and made some tweaks but theres a lot of UnknowGlobal ‘playToolAnimation’

Remove those, copy the entire script in local script to a server script which serves to animate the rig. Then if any error is outputted in the code, remove the lines that caused the error.

The problem with your solution is that the body does not exist serverside. As mentioned above, it is entirely replicated in the client. So I need to find a way to animate it trough the client. To the server, the entire rig is just a box named HumanoidRootPart.

Then copy the local script of the Animate script into client side by parenting a local script into the character model.

This wouldnt work since the localscript is a descendent of workspace

Then you’d have to connect all the necessary Humanoid events with their necessary animations.

1 Like

Found the solution. I just cloned the Animate script in playersscripts and added an object value to its character. Thanks for your time tho!