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)