I have been trying for the past 2 weeks trying to figure out how to make this fly script only let me fly for 5 seconds.Therefore, I need your guys help with only allowing "the person" to fly for 5 seconds and then have him stop flying right after. Here is the fly code I have been using. Sorry for the long code.

	repeat wait() 
		until Player and Player.Character and Player.Character:FindFirstChild("Torso") and Player.Character:FindFirstChild("Humanoid")
		repeat wait() until Mouse
		local torso = Player.Character.Torso
		local flying = true
		local deb = true
		local ctrl = {f = 0, b = 0, l = 0, r = 0}
		local lastctrl = {f = 0, b = 0, l = 0, r = 0}
		local maxspeed = 50
		local speed = 0
		
				
		function Fly()
			bg = Instance.new("BodyGyro", torso)
			bg.P = 9e4
			bg.maxTorque = Vector3.new(9e9, 9e9, 9e9)
			bg.cframe = torso.CFrame
			bv = Instance.new("BodyVelocity", torso)
			bv.velocity = Vector3.new(0,0.1,0)
			bv.maxForce = Vector3.new(9e9, 9e9, 9e9)
			repeat wait()
				Player.Character.Humanoid.PlatformStand = true
				if ctrl.l + ctrl.r ~= 0 or ctrl.f + ctrl.b ~= 0 then
					speed = speed+.5+(speed/maxspeed)
					if speed > maxspeed then
						speed = maxspeed
					end
				elseif not (ctrl.l + ctrl.r ~= ctrl.f + ctrl.b ~= 0) and speed ~= 0 then
					speed = speed - 1
					if speed < 0 then
						speed = 0
					end
				end
				if (ctrl.l + ctrl.r) ~= 0 or (ctrl.f + ctrl.b) ~= 0 then
					bv.velocity = ((game.Workspace.CurrentCamera.CoordinateFrame.lookVector * (ctrl.f + ctrl.b)) + ((game.Workspace.CurrentCamera.CoordinateFrame * CFrame.new(ctrl.l + ctrl.r,(ctrl.f + ctrl.b)*.2,0).p) - game.Workspace.CurrentCamera.CoordinateFrame.p))*speed
					lastctrl = {f = ctrl.f, b = ctrl.b, l = ctrl.l, r = ctrl.r}
				elseif (ctrl.l + ctrl.r) == 0 and (ctrl.f + ctrl.b) == 0 and speed ~=0 then
					bv.velocity = ((game.Workspace.CurrentCamera.CoordinateFrame.lookVector * (lastctrl.f + lastctrl.b)) + ((game.Workspace.CurrentCamera.CoordinateFrame * CFrame.new(lastctrl.l + lastctrl.r,(lastctrl.f + lastctrl.b)*.2,0).p) - game.Workspace.CurrentCamera.CoordinateFrame.p))*speed
				else
					bv.velocity = Vector3.new(0,0.1,0) 
				end
				bg.cframe = game.Workspace.CurrentCamera.CoordinateFrame * CFrame.Angles(-math.rad((ctrl.f + ctrl.b) * 50 * speed/maxspeed),0,0)
			until not flying
			ctrl = {f = 0, b = 0, l = 0, r = 0}
			lastctrl = {f = 0, b = 0, l = 0, r = 0}
			speed = 0
			bg:Destroy()
			bv:Destroy()
			Player.Character.Humanoid.PlatformStand = false
		end
		Mouse.KeyDown:connect(function(key)
				if key:lower() == "b" then 
				if flying then flying = false
				else
					flying = true
					Fly()
					end
			elseif key:lower() == "w" then
				ctrl.f = 1
			elseif key:lower() == "s" then
				ctrl.b = -1
			elseif key:lower() == "a" then
				ctrl.l = -1
			elseif key:lower() == "d" then
				ctrl.r = 1
			end
		end)
		Mouse.KeyUp:connect(function(key)
			if key:lower() == "w" then
				ctrl.f = 0
			elseif key:lower() == "s" then
				ctrl.b = 0
			elseif key:lower() == "a" then
				ctrl.l = 0
			elseif key:lower() == "d" then
				ctrl.r = 0
			end
		end)
		Fly()

7 comments

0

Where did you get this code?

0

You could add wait(5) and set the boolean that the scripts identifies if the person is flying or not to false..but i won't tell you where to put it since i think you're not even trying to understand the script you probably just took somewhere..

0

Well, I appreciate the Help npottl3. That's the first thing I did but i put it at the end of the script. Thanks again.

0

Plus, that script uses deprecated KeyUp and Keydown.

0

This script looks like Kohltastrophe's fly script; is this his script, and you just edited it? If so, could you please provide credit?

0
  • You didn't define "Player" (the variable) before line 1; are you showing the full script, or a snippet?
0

My suspicions were correct: this script was created by Kohltastrophe; you only indented it. Please give credit to him, as this is his script.