I am trying to make the controls for my game that move a cube according to a table I assign per change, as well as doing that without any movement delays after executing the specified keys.
The delay in movement is too frustrating for players to use, as it acts roughly 100ms after a key press due to client-server communication delays, which is too slow when it comes to platforming across the cubed map, which can be particularly difficult to navigate.
I have tried looking for NetworkOwner logic and seeing if I can utilize it here, but it only caused another error when I tried to implement it. I may be using it wrong or it might simply just not work. The Developer Hub didn’t seem to contain anything of what I need to make movement more responsive when it comes to my current game.
CODE
Server Script
local Players = game:GetService("Players")
local controls = {}
local jumpcd = {}
Players.PlayerAdded:Connect(function(plr)
controls[plr.Name] = {}
jumpcd[plr.Name] = 0
end)
local cevent = game:GetService("ReplicatedStorage").TestPlatformerRemotes:FindFirstChild("ControlEvent")
cevent.OnServerEvent:Connect(function(plr, contdata)
controls[plr.Name] = contdata
print("Pong!")
end)
game:GetService("RunService").Stepped:Connect(function()
for _,p in ipairs(Players:GetChildren()) do
local con = controls[p.Name]
local pc = p.CStats.Character.Value
if con.left and pc.AssemblyLinearVelocity.Y > -10 then
pc.AssemblyLinearVelocity = pc.AssemblyLinearVelocity + Vector3.new(-4,0,0)
elseif con.right and pc.AssemblyLinearVelocity.Y < 10 then
pc.AssemblyLinearVelocity = pc.AssemblyLinearVelocity + Vector3.new(4,0,0)
end
if pc.AssemblyLinearVelocity.Y < .6 and pc.AssemblyLinearVelocity.Y > -.6 then
if jumpcd[pc.Name] > 0 then
jumpcd[pc.Name] = jumpcd[pc.Name] - 1
end
end
if con.jump and jumpcd[pc.Name] <= 0 then
pc.AssemblyLinearVelocity = Vector3.new(pc.AssemblyLinearVelocity.X, math.random(50, 75), pc.AssemblyLinearVelocity.Z)
jumpcd[pc.Name] = 6
end
end
end)
Local Script
local UIS = game:GetService("UserInputService")
local cont = {
left = false,
right = false,
jump = false
}
local cevent = game:GetService("ReplicatedStorage").TestPlatformerRemotes:FindFirstChild("ControlEvent")
local pc = workspace["!Players"]:FindFirstChild(game:GetService("Players").LocalPlayer.Name)
game:GetService("RunService").Heartbeat:Connect(function()
local dataChanged = false
local locont = {
left = UIS:IsKeyDown(Enum.KeyCode.A),
right = UIS:IsKeyDown(Enum.KeyCode.D),
jump = UIS:IsKeyDown(Enum.KeyCode.Space)
}
if cont.left ~= locont.left then
dataChanged = true
cont.left = locont.left
elseif cont.right ~= locont.right then
dataChanged = true
cont.right = locont.right
end
if cont.jump ~= locont.jump then
dataChanged = true
cont.jump = locont.jump
end
if dataChanged then
cevent:FireServer(cont)
print("Ping!")
end
end)
Most notably, all scripts unrelated to this is working correctly. There are no errors or warnings, only an annoying movement delay that is found in live games exclusively due to the client and server no longer being emulated in the same machine.
The Player Character is a Part, and that Part exists in a workspace folder (and was temporarily put in the workspace to see if changing network owners would fix even bothering with client-server communications).
I am not sharing much more of my scripts, as I want to keep the project unique and impossible to copy effectively.
Any help and alternate methods are appreciated!