Above is a video of my rock rolling down a mountain, the movement system works by detecting Keydown and Keyup events on client and then will fireserver and make the movements happen, it work’s fine except for the input lag, and I’m assuming lag will only get worse with more players in the game. If anyone has any ideas on how to improve this system please let me know. I will include an example of my code below:
function OnKeyDown(InputType, GameProcessed)
if GameProcessed == false then
if InputType.KeyCode == Enum.KeyCode.Space then
if DroppedBool.Value == false then
Drop()
else
Jump()
end
elseif InputType.KeyCode == Enum.KeyCode.A then
Left = true
Right = false
Movement()
elseif InputType.KeyCode == Enum.KeyCode.D then
Right = true
Left = false
Movement()
elseif InputType.KeyCode == Enum.KeyCode.Left then
Left = true
Right = false
Movement()
elseif InputType.KeyCode == Enum.KeyCode.Right then
Right = true
Left = false
Movement()
end
end
end
UserInputService.InputBegan:Connect(OnKeyDown)
function OnKeyUp(InputType, GameProcessed)
if GameProcessed == false then
if InputType.KeyCode == Enum.KeyCode.A then
Left = false
elseif InputType.KeyCode == Enum.KeyCode.D then
Right = false
elseif InputType.KeyCode == Enum.KeyCode.Left then
Left = false
elseif InputType.KeyCode == Enum.KeyCode.Right then
Right = false
end
end
end
UserInputService.InputEnded:Connect(OnKeyUp)
function Movement()
while true do
if Right == true then
if Current ~= "Right" then
Current = "Right"
MovementRemote:FireServer("Right")
end
elseif Left == true then
if Current ~= "Left" then
Current = "Left"
MovementRemote:FireServer("Left")
end
else
MovementRemote:FireServer("Stop")
break
end
wait()
end
end
Sorry but for some reason it glitches when trying to put the above code in a box