How to make Fly Command?

I want to make a fly command.

I do not know how to code it.

I looked at youtube.com and I found nothing on devforum.roblox.com that could help me.

I am trying to make a fly command but I do not know how to code it in the script if you would tell me please try and explain it in as much detail as you can please. :grinning_face_with_smiling_eyes: I really hope I can make it to finish my admin commands.

commands.fly = function(sender, args)

	local playerToFly = args[1]

	if playerToFly then
		local player = findPlayer(playerToFly)

		if player then
			local body = Instance.new("BodyVelocity")
			body.Name = "FlyVelocity"
			body.Parent = player.Character.HumanoidRootPart
			body.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
			body.Velocity = Vector3.new(0,0,0)
		end
	end
	
	if args[1] == "me" then
		
		if sender then
			local body = Instance.new("BodyVelocity")
			body.Name = "FlyVelocity"
			body.Parent = sender.Character.HumanoidRootPart
			body.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
			body.Velocity = Vector3.new(0,0,0)
		end
	end
end
3 Likes

@DargoA :grinning_face_with_smiling_eyes:

So basically, you can try making a new BodyVelocity inside the player’s character’s HumanoidRootPart, set the MaxForce to Vector3.new(math.huge,math.huge,math.huge), but the velocity to Vector3.new(0,0,0) first. Then whenever the character’s Humanoid’s MoveDirection changes, request for the client’s camera’s CFrame (workspace.CurrentCamera.CFrame) and the key pressed. Sorry I’m not able to help you with things more than that, because I don’t really do much with body control in my experiences, and I also have a lot of homework to do right now. So hopefully this gives you some things you might want to use. Another thing, if you just want to make a fly command, you could just use Kohl’s Admin. Finally, if the reason you want to make a fly command is to look at the other players, you could just use Shift + P in a Roblox server and use Roblox’s built in Free Cam for the developers of the game. Anyways, gotta do homework, sorry! :sweat_smile:

1 Like

Can you show it in a script this is hurting my brain

I am sorry what that sounds just no that makes me sound like a creep

@D0RYU Can you try helping :grinning_face_with_smiling_eyes:

@Jackscarlett Can you help me please? :grinning_face_with_smiling_eyes:

I am trying to make it mobile and PC using

Oh dear

Well first off, you’ll have to detect where exactly the Humanoid is moving using the Running Event I suppose, I don’t think a BodyVelocity would be the best case in this scenario since it’ll only apply “constant force” to what you’re trying to accomplish

You could potentially send a RemoteEvent from the client to the server, so that it’d detect the UserInputService.InputBegan/InputEnded events depending on which key you pressed (W, A, S, D) to make the Character in that specific way

Thing with using mobile, is that you’ll have to find a wrap-around on getting where the Character would face next in relation to the thumbstick

There’s a lot to keep in mind with a simple fly command, maybe you could use a BodyForce instead so that it only applies “force” when necessary but I’m unsure

This is my assumption

1 Like

Can you try and show me what you mean for it? I am sorry for asking.

And I would need to have 2 remote events because I tried calling commands inside of local it doesnt work but thats fine I will do that I just need an example

	
	local char = player.Character
	local humanoid = char:FindFirstChild("Humanoid")
	
	body = Instance.new("BodyVelocity")
	body.Name = "FlyVelocity"
	body.Parent = player.Character.HumanoidRootPart
	body.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
	body.Velocity = Vector3.new(0,0,0)
	
	game.ReplicatedStorage:WaitForChild("ServerCommand"):FireServer()

I got this rn

--LocalScript inside StarterPlayerScripts
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local UIS = game:GetService("UserInputService")

local MovesetKeys = {
   Enum.KeyCode.A, --This would be left
   Enum.KeyCode.D, --Right
   Enum.KeyCode.W, --Forwards
   Enum.KeyCode.S --Backwards
}

local CurrentKeyHit = nil --There's no current key set

UIS.InputBegan:Connect(function(Input, Chatted)
    if Chatted then
        return
    end

    if table.find(MovesetKeys, Input.KeyCode) then

        if Input.KeyCode == MovesetKeys[1] then
            CurrentKeyHit = "Left"
        elseif Input.KeyCode == MovesetKeys[2] then
            CurrentKeyHIt = "Right"
        elseif Input.KeyCode == MovesetKeys[3] then
            CurrentKeyHit = "Forwards"
        elseif Input.KeyCode == MovesetKeys[4] then
            CurrentKeyHit = "Backwards"
        else
            CurrentKeyHit = nil
        end

        Event:FireServer(CurrentKeyHit)
    end
end)
--Server Script inside ServerScriptService
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")

Event.OnServerEvent:Connect(function(Player, Key)
    local BodyForce
    local Char = Player.Character
   
    if Char.HumanoidRootPart:FindFirstChild("BodyForce") then
        BodyForce = Char.HumanoidRootPart.BodyForce
    else
        local Force = Instance.new("BodyForce")
        Force.Parent = Char.HumanoidRootPart
        BodyForce = Force
    end

    if Key == "Left" then
        BodyForce.Force = Char.HumanoidRootPart.RightVector * -25
    elseif Key == "Right" then
        BodyForce.Force = Char.HumanoidRootPart.RightVector * 25
    elseif Key == "Forwards" then
        BodyForce.Force = Char.HumanoidRootPart.LookVector * 25
    elseif Key == "Backwards" then
        BodyForce.Force = Char.HumanoidRootPart.LookVector * -25
    end
end)

This is again, an assumption

Keep in mind that I have no idea how flying works

Will it work in startergui? that is where mine is located.

It’ll work anywhere as long as it’s replicated across the local side, so yes

Ok thank you I am testing it in a second

Will it work if I do a unfly command?

It says there is no such thing as RightVector

@Jackscarlett :grinning_face_with_smiling_eyes:

@Jackscarlett