[HELP] Fly Script Not Stopping

Hi I Testing Make A Fly Script My Fly Script Not Stopping Help Please

Code :

local player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local flying = false

player.CharacterAdded:Connect(function(chr)
	local humanoid = chr:WaitForChild("Humanoid")
	local humanoidrootpart = chr:WaitForChild("HumanoidRootPart")
	local uppertorso = chr:WaitForChild("UpperTorso")
	
	local bodyvelocity = Instance.new("BodyVelocity",uppertorso)
	bodyvelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
	bodyvelocity.Velocity = Vector3.new(0,1,0)
	
	UIS.InputBegan:Connect(function(key)
		if key.KeyCode == Enum.KeyCode.W then
			flying = true
			print("pressing w")
			while flying == true do wait()
				bodyvelocity.Velocity = humanoidrootpart.CFrame.LookVector * 100
			end
		end
	end)
	
	UIS.InputEnded:Connect(function(key)
		if key.KeyCode == Enum.KeyCode.W then
			flying = false
			print("press w ended")
		end
	end)
end)
1 Like

You need to remove the velocity from the bodyvelocity for it to stop.

while flying == true do wait()
	bodyvelocity.Velocity = humanoidrootpart.CFrame.LookVector * 100
end
bodyvelocity.Velocity = Vector3.new(0, 0, 0)
1 Like

how i can make smooth stopping ?

Tween the Y-axis of the BodyVelocity’s Velocity property down to 0.

1 Like