I need help with flying script

So I got some help with making this flying script but it’s still a little bit weird so I needed some help from other people

So Some issues with my script are that when I unequip my wings, I still fly, so I wanted to know how to make a script that can disable flying when you unequip wings. Also when I equip my wings the player is facing to the left which is a bit weird. (Btw the wings is the tool so just experiment with a plain block with a handle)

Script:

local uis = game:GetService("UserInputService")
local rs = game:GetService("RunService")
wait(5)
local myPlayer = game.Players.LocalPlayer
local myChar = myPlayer.Character
local myHRP = myChar:WaitForChild("HumanoidRootPart")
local camera = game.Workspace.CurrentCamera
local LastTapped, Tapped = false, false
local flyUpSpeed = 20
local flyDownSpeed = 20
local wdown = false
local toggle = false
local flying = false
local speed = 0.5
local bp = nil
local bg = nil
local bodyVel = nil

function fly()
	bp = Instance.new("BodyPosition",myHRP)
	bp.MaxForce = Vector3.new()
	bp.D = 100
	bg = Instance.new("BodyGyro",myHRP)
	bg.MaxTorque = Vector3.new()
	bg.D = 100
	flying = true
	bp.Position = myHRP.Position + Vector3.new(0,10,0)
	bp.MaxForce = Vector3.new(400000,400000,400000)
	bg.MaxTorque = Vector3.new(400000,400000,400000)
end
while flying do
	rs.RenderStepped:wait()
	bp.Position = myHRP.Position +((myHRP.Position - camera.CFrame.p).unit * speed)
	bg.CFrame = CFrame.new(camera.CFrame.p, myHRP.Position)
end
uis.InputBegan:connect(function(Input)
	if Input.KeyCode == Enum.KeyCode.W and flying == true and wdown == false then
		if toggle == false then
			bp:Destroy()
			wdown = true
			bodyVel = Instance.new("BodyVelocity",myHRP)
			bodyVel.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
			while flying and wait() do
				bodyVel.Velocity = camera.CFrame.LookVector*speed*80
			end
		end

	end
end)

uis.InputEnded:Connect(function(Input)
	if Input.KeyCode == Enum.KeyCode.W and flying == true and wdown == true then
		if toggle == false then
			wdown = false
			bodyVel:Destroy()
			bp = Instance.new("BodyPosition",myHRP)
			bp.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
			bp.D = 100
			bp.Position = myHRP.Position
		end
	end
end)

function endFlying()
	bp:Destroy()
	bg:Destroy()
	flying = false
end


uis.InputBegan:connect(function(input)
	if input.KeyCode == Enum.KeyCode.Space then
		if Tapped == false then
			Tapped = true
		else
			LastTapped = true
			Tapped = false
			if not flying then
				fly()
			else
				endFlying()
			end
		end
	end
end)

1 Like

Could you please format it better?

1 Like

To format it better use ``` and close it with the same thing

1 Like

Wait im confused (sorry I’m kinda new)

1 Like

So wait, I edited it is it like this?

1 Like

Have it like this

"```
--Code Here
print(Code)
"```

Note: I had to put the " there to be able to show the key

1 Like

Okay so I finally did it I think

1 Like

Yes But I don’t know how you got the > any way that doesn’t really matter

1 Like

Oh well at least you can read my code and see what is wrong with it

1 Like

Oh I forgot to tell you that fixed it