An Efficient Method To Move Player From ClientSide (detecting inputs) to ServerSide

Below is the code I’m currently using, however, the player is lagging so much and it’s not actually smooth at all. I’ve tried switching from RenderStepped to Heartbeat for physics-related and it didn’t work tho. I’ve also added the frequency to multiply it by the change of time during the Heartbeat. Nothing seems to have worked.

local function startDescend(HRP)
	local frequency = 10
	local connection
	
	connection = RunService.Heartbeat:Connect(function(dt)
		if not UserInputService:IsKeyDown(Enum.KeyCode.Space) or detectGround() then
			connection:Disconnect()			
			return
		end
		
		SetPlayerPos:FireServer(HRP.CFrame * CFrame.new(0, -frequency, 0))
		-- HRP.CFrame = HRP.CFrame * CFrame.new(0, -frequency * dt, 0)
	end)
end
2 Likes

Firing a RemoteEvent 60 times a second isn’t really good for performance…

What you are doing is already in Roblox

Client owns their character (Ownership)
Client moves their character, replicates to server and other clients.
It’s most smooth for the client tho

Um, no?
Server:


Client:

How about using this codes?

local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")

local isDescending = false
local descendConnection

local function startDescend(HRP)
	local frequency = 10

	if isDescending then return end
	isDescending = true

	descendConnection = RunService.Heartbeat:Connect(function(dt)
		if not UserInputService:IsKeyDown(Enum.KeyCode.Space) or detectGround() then
			descendConnection:Disconnect()
			isDescending = false
			return
		end

		HRP.CFrame = HRP.CFrame * CFrame.new(0, -frequency * dt, 0)
	end)
end

UserInputService.InputBegan:Connect(function(input, gameProcessed)
	if gameProcessed then return end
	if input.KeyCode == Enum.KeyCode.Space then
		local HRP = game.Players.LocalPlayer.Character and game.Players.LocalPlayer.Character:FindFirstChild("HumanoidRootPart")
		if HRP then
			startDescend(HRP)
		end
	end
end)

That’s the same thing as I’m doing just in a different approach. What I’m trying to do is to replicate the movement in both client and server smoothly.

So, instead of running it in code, how about trying to leverage the physics engine using AssemblyLinearVelocity?

1 Like

Alrighty! I’ll try that out, since I’ve never touched it before.

I ended up actually using the rope’s physics by increasing the length to make the player down. I was using a custom CFrame update which was using a lot of resources.

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