Calling Remote Event affects Client

I’ve got a simple character controller script that controls a skinned mesh rig, and I update the rig’s position to the server with a event and server script, so everyone can see the character move ofcourse, and the moving instance is a bone.

But when I fire the remotevent using FireServer() and sending the input of the bone to update to the server, it just messes up the client. I can’t walk in any direction when i move the camera (camera is also custom scripted) and im only locked into moving in the X and Z axis. The jittering also happens on the server.

Heres a video showing the glitch thing

And here’s my server script, see if anyone can find a problem that i can’t. I’ll send the client script if someone asks

local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CharacterModel = ReplicatedStorage:WaitForChild("R6")
local SpawnPlayerModel = ReplicatedStorage:WaitForChild("SpawnPlayerModel")
local MovePlayerModel = ReplicatedStorage:WaitForChild("MovePlayerModel")

SpawnPlayerModel.OnServerEvent:Connect(function(player)
	local characterClone = CharacterModel:Clone()
	characterClone.Name = player.Name
	characterClone.Parent = workspace

	if characterClone then
		for _, child in characterClone:GetChildren() do
			if child:IsA("BasePart") then
				child:SetNetworkOwner(player)
			end
		end
	end
end)

MovePlayerModel.OnServerEvent:Connect(function(player, input)
	local character = workspace:FindFirstChild(player.Name)
	if character then
		local Root = character:FindFirstChild("RootPart").Root
		if Root then
			local config = {
				Speed = 16,
			}

			local MovementVector = Vector3.new(input.MovementX, 0, input.MovementY).Unit

			if MovementVector.Magnitude > 0 then
				Root.WorldCFrame = Root.WorldCFrame * CFrame.new(MovementVector * config.Speed * RunService.Heartbeat:Wait())
			end

                        -- still working on this part
			if input.Jump then
				Root.WorldCFrame = Root.WorldCFrame + Vector3.new(0, 5, 0)
			end
		end
	end
end)

I mean I know that, the gittering is caused by client-server lag. Its to be expected ig

Just thought it would be helpful. And my main problem is the client, dont really care about the server lag

1 Like

Could you also show the client script?

local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local SpawnPlayerModel = ReplicatedStorage:WaitForChild("SpawnPlayerModel")
local MovePlayerModel = ReplicatedStorage:WaitForChild("MovePlayerModel")

SpawnPlayerModel:FireServer(Players.LocalPlayer)

local Character = {
	Model = workspace:WaitForChild(Players.LocalPlayer.Name),
}

local Bones = {
	Root = Character.Model.RootPart.Root,
	UpperTorso = {},
	LowerTorso = {},
}

local Input = {
	keysDown = {},
	previousKeysDown = {},
}

local Camera = {
	Target = Bones.Root,
	AngleX = 0,
	AngleY = 0,
	MaxAngleX = 80,
	Sensitivity = 0.125,
	MouseDelta = Vector2.new(0, 0),
	CurrentCamera = workspace.CurrentCamera,
}

function Input.start()
	UserInputService.InputBegan:Connect(function(inputObject)
		if inputObject.UserInputType ~= Enum.UserInputType.Keyboard then
			return
		end

		Input.keysDown[inputObject.KeyCode] = true
	end)

	UserInputService.InputEnded:Connect(function(inputObject)
		if inputObject.UserInputType ~= Enum.UserInputType.Keyboard then
			return
		end

		Input.keysDown[inputObject.KeyCode] = nil
	end)
end

function Input.step()
	local newKeysDown = {}

	for key, value in pairs(Input.keysDown) do
		newKeysDown[key] = value
	end

	Input.previousKeysDown = Input.keysDown
	Input.keysDown = newKeysDown
end

local function setupCamera()
	Camera.CurrentCamera.CameraSubject = nil
	Camera.CurrentCamera.CameraType = Enum.CameraType.Scriptable
	
	UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
end

function Camera.step()
	local Height = 3
	local Distance = 0

	Camera.MouseDelta = UserInputService:GetMouseDelta()
	
	Camera.AngleX = math.clamp(Camera.AngleX - Camera.MouseDelta.Y * Camera.Sensitivity, -Camera.MaxAngleX, Camera.MaxAngleX)
	Camera.AngleY = Camera.AngleY - Camera.MouseDelta.X * Camera.Sensitivity

	local Yaw = CFrame.Angles(0, math.rad(Camera.AngleY), 0) -- Yaw rotation
	local Pitch = CFrame.Angles(math.rad(Camera.AngleX), 0, 0) -- Pitch rotation
	
	local Position = Camera.Target.WorldCFrame.Position + Vector3.new(0, Height, Distance)

	Camera.CurrentCamera.CFrame = CFrame.new(Position) * Yaw * Pitch
	
	Camera.Target.WorldCFrame = CFrame.new(Camera.Target.WorldCFrame.Position) * CFrame.fromEulerAnglesXYZ(0, math.rad(Camera.AngleY), 0)
	
	setupCamera()
end

RunService.Stepped:Connect(function(_, deltaTime)
	local input = {
		MovementX = 0,
		MovementY = 0,
		Jump = Input.keysDown[Enum.KeyCode.Space] and not Input.previousKeysDown[Enum.KeyCode.Space],
	}
	
	local config = {
		Speed = 16,
	}

	if Input.keysDown[Enum.KeyCode.W] then
		input.MovementY = input.MovementY - 1
	end

	if Input.keysDown[Enum.KeyCode.S] then
		input.MovementY = input.MovementY + 1
	end

	if Input.keysDown[Enum.KeyCode.D] then
		input.MovementX = input.MovementX + 1
	end

	if Input.keysDown[Enum.KeyCode.A] then
		input.MovementX = input.MovementX - 1
	end
	
	MovePlayerModel:FireServer(input)

	local MovementVector = Vector3.new(input.MovementX, 0, input.MovementY).Unit
	
	if MovementVector.Magnitude > 0 then
		local moveCFrame = CFrame.new(MovementVector * config.Speed * deltaTime)
		Bones.Root.WorldCFrame = Bones.Root.WorldCFrame * moveCFrame
	end

	if input.jump then
		Bones.Root.WorldCFrame = Bones.Root.WorldCFrame + Vector3.new(0, 5, 0)
	end
	
	Input.step()
	Camera.step()
end)

Input.start()

I think it may be jittering because you send an event every physics simulation frame. It would also horribly lag for people with bad connection or low framerates.

I see, I’ll look into it further

1 Like

Moving the character using CFrames doesn’t have interpolation, which is what makes the movements look smooth. If you’re using CFrames to update the position this might be the problem.

To hide the interpolation that @BendsSpace mentioned you could try to use :Lerp on the server to make it look smooth

It will probably still lag tho, the delay between Client - Server might just be too big

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.