Issue with custom character replication!

Hi !
I made a script that move a custom character !
Here the script :

local UserInputService = game:GetService("UserInputService")
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 Character = Player.Character
local Distance = Instance.new("NumberValue")
local Camera = workspace.CurrentCamera

local function GetParts()
	local Parts = {}
	for v, Part in pairs(Character:GetChildren()) do
		if Part:IsA("BasePart") then
			table.insert(Parts, Part)
		end
	end
	return Parts
end

local function GetBiggestPart()
	local BiggestPart
	for v, Part in pairs(GetParts(Character)) do
		if BiggestPart == nil or BiggestPart.Size.Z < Part.Size.Z then
			BiggestPart = Part
		end
	end
	return BiggestPart
end

local function GetDifference()
	return Camera.ViewportSize * 0.5 - UserInputService:GetMouseLocation()
end

local function GetSpeed(Part)
	local Speed = GetDifference().Magnitude / (Camera.ViewportSize.Y / 2)
	local Value = GetBiggestPart().Size.Z / Part.Size.Z
	if Value > 2 then
		Value = 2
	end
	if Speed >= 1 then
		return Value
	else
		return Speed * Value
	end
end

local function GetPosition(Part)
	local Speed = GetSpeed(Part)
	local Difference = GetDifference()
	local X = Difference.Y
	local Z = Difference.X
	local Denominator = math.abs(X) + math.abs(Z)
	local XPercentage = math.abs(X) / Denominator * math.sign(X) * -1
	local ZPercentage = math.abs(Z) / Denominator * math.sign(Z)
	local Percentage = 1 / math.sqrt(XPercentage^2 + ZPercentage^2)
	XPercentage *= Percentage
	ZPercentage *= Percentage
	return Part.Position + Vector3.new((XPercentage * Speed) / 4, 0, (ZPercentage * Speed) / 4)
end

local function GetDistance(Size, Percentage)
	return Size / Percentage / math.tan(math.rad(35)) / 2
end

local function SetDistance(Parts, Part)
	local MinX = math.huge
	local MaxX = -math.huge
	local MinZ = math.huge
	local MaxZ = -math.huge
	for v, Part in pairs(Parts) do
		if Part.Position.X - Part.Size.X / 2 < MinX then
			MinX = Part.Position.X - Part.Size.X / 2
		end
		if Part.Position.X + Part.Size.X / 2 > MaxX then
			MaxX = Part.Position.X + Part.Size.X / 2
		end
		if Part.Position.Z - Part.Size.Z / 2 < MinZ then
			MinZ = Part.Position.Z - Part.Size.Z / 2
		end
		if Part.Position.Z + Part.Size.Z / 2 > MaxZ then
			MaxZ = Part.Position.Z + Part.Size.Z / 2
		end
	end
	local X = math.abs(MinX - MaxX)
	local Z = math.abs(MinZ - MaxZ)
	local XDistance
	local ZDistance
	if #Parts > 1 then
		XDistance = GetDistance(X, 0.5)
		ZDistance = GetDistance(Z, 0.5)
	else
		XDistance = GetDistance(X, 0.2)
		ZDistance = GetDistance(Z, 0.2)
	end
	if XDistance > ZDistance then
		Distance.Value = XDistance
	else
		Distance.Value = ZDistance
	end
end

local function SetCameraCFrame()
	local Parts = GetParts(Character)
	SetDistance(Parts, GetBiggestPart())
	local Position = Vector3.new(0, 0, 0)
	for v, Part in pairs(Parts) do
		Position += Vector3.new(Part.Position.X, 0, Part.Position.Z)
	end
	Position /= #Parts
	Camera.CFrame = CFrame.new(Position + Vector3.new(0, Distance.Value, 0)) * CFrame.Angles(math.rad(-90), 0, math.rad(90))
end

local function Update()
	for v, Part in pairs(GetParts()) do
		Part.Position = GetPosition(Part)
	end
	SetCameraCFrame()
end

local function GetInformations()
	local Informations = {}
	for v, Part in pairs(GetParts()) do
		table.insert(Informations, {Part, Part.Position})
	end
	return Informations
end

RunService.RenderStepped:Connect(Update)

How it’s look like :


The only problem is that this movement isn’t replicated to the server !
How could I replicate it ?
Have a nice day and thanks you for the reply !

In most case (except specific rare occasions like the player object) localscript actions does not replicate to the server thanks to the filtering service. I sadly can’t help you with this issues since I do not have the knowledge for it but I can give you a hint. You need to use Network Ownership to replicate the client-side to the server-side

Here some resources, good luck

1 Like

I tried but my part is anchored …
Thanks you for the reply !

If you can not use NetworkOwnership just use a RemoteEvent and pass it through the server.

1 Like

Using remoteEvents for continuous character movement is a really bad idea. If several players are present in the game, or if several requests are sent quite enought, all remoteEvents will be “rateLimited”. Also, remoteEvents and remoteFunctions have a limited amount of data they can send per request.

1 Like

Unanchoring it and letting Roblox take care of the problem is probably the easiest method, otherwise, you must communicate your inputs/character positions to the server and update the model (or another model) on the server, using remotes.

1 Like

I have done this with remote function and it work better than before !
Thanks you !