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)