Feedback on my Flying keybind

robloxapp-20201016-1835022.wmv (1.5 MB)

I made it with F.

To do this make a LocalScript.

Put it into StarterPack.

then put in the script

repeat wait() until game.Players.LocalPlayer.Character

local plr = game.Players.LocalPlayer
local char = plr.Character
local hum = char:WaitForChild("Humanoid")
local Torso = char:WaitForChild("LowerTorso")
local Mouse = plr:GetMouse()
local toggle = false

Mouse.KeyDown:Connect(function(key)
	if key == "f" then
		if toggle == false then
			toggle = true
			local Anim = Instance.new("Animation")
			Anim.AnimationId = "rbxassetid://5777401826"
			local PlayAnim = hum:LoadAnimation(Anim)
			PlayAnim:Play()
			local BV = Instance.new("BodyVelocity",Torso)
			BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
			while toggle == true do
				BV.Velocity = Mouse.Hit.lookVector*100
				wait()
			end
		end
		if toggle == true then
			toggle = false
			Torso:FindFirstChildOfClass("BodyVelocity"):remove()
			local tracks = hum:GetPlayingAnimationTracks()
			for i, stoptracks in pairs(tracks) do
				stoptracks:Stop()
			end
			local Anim = Instance.new("Animation")
			Anim.AnimationId = "http://www.roblox.com/asset/?id=507767968"
			local PlayAnim = hum:LoadAnimation(Anim)
			PlayAnim:Play()
		end
	end
end)

Would you mind formatting your code so it’s easier to read? It will help us help you better

Any reason you are using math.huge for your MaxForce values rather than just setting your own values? Seems a little pointless to me.

Edited because the feature’s release I originally referred to was pushed back.

I tried to optimize your code as much as I can:

-- // Variables \\ --

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local Mouse = plr:GetMouse()

local hum = char:WaitForChild(“Humanoid”)
local Torso = char:WaitForChild(“LowerTorso”)

local toggle = false

-- // Events \\ --

Mouse.KeyDown:Connect(function(key)
    if key == “f” then
        toggle = not toggle
        
        if toggle then

            local Anim = Instance.new(“Animation”)
            Anim.AnimationId = “rbxassetid://5777401826”
            local PlayAnim = hum:LoadAnimation(Anim)
            PlayAnim:Play()

            local BV = Instance.new(“BodyVelocity”, Torso)
            BV.MaxForce = Vector3.new(math.huge, math.huge, math.huge)

            while toggle do
                BV.Velocity = Mouse.Hit.lookVector * 100
                wait()
            end
        elseif not toggle then

            Torso:FindFirstChildOfClass(“BodyVelocity”):remove()
            local tracks = hum:GetPlayingAnimationTracks()

            for i, stoptracks in pairs(tracks) do
                stoptracks:Stop()
            end

            local Anim = Instance.new(“Animation”)
            Anim.AnimationId = “http://www.roblox.com/asset/?id=507767968”
            local PlayAnim = hum:LoadAnimation(Anim)
            PlayAnim:Play()
        end
    end
end)

Can’t guarantee I didn’t accidentally break something. Tell me if you don’t get something I did

Edit: I changed something that might have broken it

1 Like

it still works like that you can edit it if you want.

You broke the repeat. It wont work.

Test it now

Uhm sure ill mesage you if works.

It does not work.

It dosent allow you to start flying.