Fly System - Movements

Hi, I would like to create a way to fly but I would like to know how I can do this kind of movement: W+A, W+D, Space+D, etc.

Server :

rs.FlyMovement.OnServerEvent:Connect(function(plr, keys) 
	local char = plr.Character
	
	if keys[1] == "W" then
		char:PivotTo(char:GetPivot() * CFrame.new(0,0,-1))
	elseif keys[1] == "S" then
		char:PivotTo(char:GetPivot() * CFrame.new(0,0,1))
	elseif keys[1] == "D" then
		char:PivotTo(char:GetPivot() * CFrame.new(1,0,0))
	elseif keys[1] == "A" then
		char:PivotTo(char:GetPivot() * CFrame.new(-1,0,0))
	elseif keys[1] == "Space" then
		char:SetPrimaryPartCFrame(char:GetPrimaryPartCFrame() + Vector3.new(0,1,0))
	elseif keys[1] == "LeftShift" then
		char:SetPrimaryPartCFrame(char:GetPrimaryPartCFrame() + Vector3.new(0,-1,0))
	elseif keys[1] == "Pivot" and #keys == 3 then
		char:PivotTo(CFrame.new(keys[2], keys[3]))
	end
end)

Client :

local Moving = false
local rightclicking = false

local movementKeys = {
	[Enum.KeyCode.W] = "W",
	[Enum.KeyCode.S] = "S",
	[Enum.KeyCode.A] = "A",
	[Enum.KeyCode.D] = "D",
	[Enum.KeyCode.LeftShift] = "LeftShift",
	[Enum.KeyCode.Space] = "Space"
}

local function handleMovement(key)
	if Moving then return end
	Moving = true
	while Moving do
		rs.FlyMovement:FireServer({key})
		task.wait(0.01)
	end
end

local function handleRightClick()
	local isAble = plr.Database.isAbleFly.Value
	local char = plr.Character
	rightclicking = true
	while rightclicking and isAble do
		local pivot = char:GetPivot()
		rs.FlyMovement:FireServer({"Pivot", pivot.Position, mouse.Hit.Position})
		task.wait(0.01)
	end
end

UIS.InputBegan:Connect(function(input, isTyping)
	if not isTyping then
		local isAble = plr.Database.isAbleFly.Value
		local key = movementKeys[input.KeyCode]

		if key and isAble then
			handleMovement(key)
		end
	end
end)

UIS.InputEnded:Connect(function(_, isTyping)
	if not isTyping then
		if not Moving then return end
		Moving = false
	end
end)

mouse.Button2Up:Connect(function()
	rightclicking = false
end)

mouse.Button2Down:Connect(function()
	handleRightClick()
end)

you will probably need to use Body Movers (Constraints), that’s what i would do

I remember using bodypositions, you could store a seperate vector3 value for each key and combine them plus the current position to have the bodyposition move you to the correct location. Similar can be done with a bodygyro for rotation

i’ve made a topic about flight before (though not specifically how to create flight, but to solve an issue relating to flight) which might have some helpful information

Do you have an example to give more details?

I am not sure to understand what you done :(, can you explain please?

If you want me to explain the script (if so, look at the second one, NOT the first), I basically had 4 variables v1, v2, v3, and v4 which were vector3 values that would correspond to the WASD keys. Then I added them along with my current position to a bodyposition so it could move the character to the correct location. The bodygyro is used so the player would turn towards the direction the camera is facing

And what I do with these Vec3 ?

you add all of them together with the vector3 value of the humanoid root part (CFrame.location) and then set the bodyposition’ vector3 to that

why not just have this in all one local script, client has control over their character so no need for server sided code

besides that not sure what you are trying to do