Need some helps with player input

I made a custom movement engine that takes keyboard inputs from the player and send them to the server, but this causes some very annoying lag. Is there a better but still secure way to do this?
local script:

game.ReplicatedStorage.playerInput:FireServer({camera:GetAttribute("actualcframe"),{if key:IsKeyDown(119) then 1 else 0-if key:IsKeyDown(115) then 1 else 0,if key:IsKeyDown(100) then 1 else 0-if key:IsKeyDown(97) then 1 else 0,if key:IsKeyDown(101) then 1 else 0-if key:IsKeyDown(113) then 1 else 0,if key:IsKeyDown(117) then 1 else 0-if key:IsKeyDown(106) then 1 else 0,if key:IsKeyDown(104) then 1 else 0-if key:IsKeyDown(107) then 1 else 0,if key:IsKeyDown(105) then 1 else 0-if key:IsKeyDown(121) then 1 else 0,key:IsKeyDown(118)}})

server script:

game.ReplicatedStorage.playerInput.OnServerEvent:Connect(function(player,controller)
	local tank=game.Workspace[player.Name.." tank"]
	tank.CFrame=(controller[1] - controller[1].Position) + tank.Position
	player:SetAttribute("velocity",player:GetAttribute("velocity")+tank.CFrame.LookVector*player:GetAttribute("speed")*controller[2][1])
	player:SetAttribute("velocity",player:GetAttribute("velocity")+tank.CFrame.RightVector*player:GetAttribute("speed")*controller[2][2])
	player:SetAttribute("velocity",player:GetAttribute("velocity")+tank.CFrame.UpVector*player:GetAttribute("speed")*controller[2][3])

	player:SetAttribute("velocity",player:GetAttribute("velocity")*0.9)
	tank.CFrame+=player:GetAttribute("velocity")

	local cannon=game.Workspace[player.Name.." cannon1"]
	cannon.CFrame=tank.CFrame.Rotation*CFrame.Angles(0,math.rad(90),0)+(tank.CFrame.Position+tank.CFrame.LookVector*25)
	game.ReplicatedStorage.moveCamera:FireClient(player,controller)
end)
1 Like

Nope movement should especially be done on the client, if you’re worried about security run checks on the server to make sure nobody is doing anything weird with the movement. (also exploits wont even abuse the movement system you have - they’ll just add movement to themselves).

1 Like

Alright thanks, but how do I sync the custom player objects to the server? Would the lag from that be a problem?

Im thinking about sticking the players to their own tank and rendering the enemy tanks locally, would that work?

Uh, if i’m getting this right, you’d want all the tanks to be local (aka. client-sided) and yeah you could do that, you’d just have to replicate all movement to everyone’s client and the creation of the tank to every individual client. Now, this gets a little bit weird/complicated once you get into predictions, clean-up, replicating tanks to players just joining the server.

I think (I could be wrong) some games like World Zero have there character models replicated on the client, but I don’t know if they replicate all the movement or if there is an easier or different method.

Do I still need a remote function to update the position of the humanoids?

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