How can I make this script a lot smoother when remote is fired?

Hi there, I have a script that continuously fires a remote when a key is held. The issue is, is that it sometimes lags out and even crashes. I’m trying to make a part movewhile the remote is firing, but it’s unsmooth yet very laggy. How can I make the movement of a part a lot smoother when a remote is fired while also maintaining the lowest remotes fired?

ls

local UIS = game:GetService("UserInputService")

local forward = game.ReplicatedStorage:WaitForChild("forward")
local reverse = game.ReplicatedStorage:WaitForChild("reverse")
local left = game.ReplicatedStorage:WaitForChild("left")
local right = game.ReplicatedStorage:WaitForChild("right")

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.T then
		forward:FireServer(true)
	end

	if input.KeyCode == Enum.KeyCode.G then
		reverse:FireServer(true)
	end

	if input.KeyCode == Enum.KeyCode.F then
		left:FireServer(true)
	end

	if input.KeyCode == Enum.KeyCode.H then
		right:FireServer(true)
	end
end)
UIS.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.T then
		forward:FireServer(false)
	end

	if input.KeyCode == Enum.KeyCode.G then
		reverse:FireServer(false)
	end

	if input.KeyCode == Enum.KeyCode.F then
		left:FireServer(false)
	end

	if input.KeyCode == Enum.KeyCode.H then
		right:FireServer(false)
	end
end)

ss

local isForward = false
local isReverse = false
local isLeft = false
local isRight = false
forward.OnServerEvent:Connect(function(player,pressed)
	if player.Name == "vxsqi" then
		isForward = pressed
	end
end)

reverse.OnServerEvent:Connect(function(player,pressed)
	if player.Name == "vxsqi" then
		isReverse = pressed
	end
end)

left.OnServerEvent:Connect(function(player,pressed)
	if player.Name == "vxsqi" then
		isLeft = pressed
	end
end)
right.OnServerEvent:Connect(function(player,pressed)
	if player.Name == "vxsqi" then
		isRight = pressed
	end
end)

game:GetService("RunService").Heartbeat:Connect(function()
	if isForward then
		Part0.CFrame = Part0.CFrame * CFrame.new(0,0,0.5)
	end
	if isReverse then
		Part0.CFrame = Part0.CFrame * CFrame.new(0,0,-0.5)
	end
	if isLeft then
		Part0.CFrame = Part0.CFrame * CFrame.Angles(0,0.025,0)
	end
	if isRight then
		Part0.CFrame = Part0.CFrame * CFrame.Angles(0,-0.025,0)
	end
end)
2 Likes

I think there’s really nothing you can do, your firing to much remote events to the server.

1 Like

Not sure about this method but it will work

try to move the part in the client
detect if the part is moving by using Changed:Connect()
fire a remote event with a debounce (at least task.wait(0.1))
smooth the movement on the server by using TweenService

–SkyQuest

1 Like