How would i make this wingsuit script make you lose velocity when going up and gain velocity when going down?

wait()
local plr = game.Players.LocalPlayer
local character = plr.Character
local humanoid = character:WaitForChild("Humanoid")
local FlyAttemp = false
local UIS = game:GetService("UserInputService") 
local Float = false
local DB = false
local Flying = false
local Mouse = game.Players.LocalPlayer:GetMouse()

local VelVal = script.CurrVel

local FlyAnim =  humanoid:LoadAnimation(script.Flying)
FlyAnim.Priority = Enum.AnimationPriority.Movement

local stamdb = false

local nofuel = false

local landed = true

script.Parent.FlightLeft.Changed:Connect(function()
	if script.Parent.FlightLeft.Value == 0 then
		script.Parent.Parent.Visible = false
		humanoid:ChangeState(Enum.HumanoidStateType.Freefall)
		script.Parent.FlightLeft.Value = 0
		wait(1)
		game.ReplicatedStorage.Wingsuit.Value = false
		wait(3)
		script.Parent.FlightLeft.Value = 100
		nofuel = false
	end
end)

humanoid.StateChanged:Connect(function(oldState, newState)
	if newState == Enum.HumanoidStateType.Jumping or newState == Enum.HumanoidStateType.Freefall then
		if not FlyAttemp then
			FlyAttemp = true
		end
	elseif newState == Enum.HumanoidStateType.Landed then
		landed = true
		if FlyAttemp then
			FlyAttemp = false
		end
	elseif oldState == Enum.HumanoidStateType.Landed then
		landed = false
	end
end)


UIS.InputBegan:Connect(function(key,Chatting)
	if Chatting then return end
	if key.KeyCode == Enum.KeyCode.X then
		Flying = true
		if DB == false then
			DB = true
			if FlyAttemp and script.Parent.FlightLeft.Value == 100 then
				script.Parent.Parent.Visible = true
				script.Equip:Play()
				script.Wind:Play()
				Float = true
				if Float then
					local FloatVelocity = Instance.new("BodyVelocity")
					FloatVelocity.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
					character.HumanoidRootPart.CFrame = character.HumanoidRootPart.CFrame + Vector3.new(0,5,0)
					FloatVelocity.Velocity = Vector3.new(0,0,0)
					FloatVelocity.Name = "FloatVelocity"
					FloatVelocity.Parent = character.HumanoidRootPart
					game:GetService("RunService").RenderStepped:Connect(function()
						if Flying and Float then
							game.ReplicatedStorage.Wingsuit.Value = true

							FlyAnim:Play()

							local MousePos = Mouse.Hit.p

							local lookVector = Vector3.new(MousePos.X,MousePos.Y,MousePos.Z)

							local floaty = FloatVelocity.Velocity.Y

							character.HumanoidRootPart.CFrame = CFrame.new(character.HumanoidRootPart.CFrame.p,lookVector)
							FloatVelocity.Velocity = Mouse.Hit.lookVector * VelVal.Value

							if floaty < 50 then
								VelVal.Value += 1
								wait(0.1)
							end

							if FloatVelocity.Velocity.Y >= 40 then
								VelVal.Value -= 25
								wait(0.25)
							end

							if VelVal.Value <= 0 then
								Flying = false
								Float = false
								DB = true
								script.Wind:Stop()
								FlyAnim:Stop()	
								VelVal.Value = 1
								if character.HumanoidRootPart:FindFirstChild("FloatVelocity") then
									character.HumanoidRootPart:FindFirstChild("FloatVelocity"):Destroy()	
								end
							end				

							if script.Parent.FlightLeft.Value == 0 then
								Flying = false
								Float = false
								DB = true
								script.Wind:Stop()
								FlyAnim:Stop()		
								VelVal.Value = 1	
								if character.HumanoidRootPart:FindFirstChild("FloatVelocity") then
									character.HumanoidRootPart:FindFirstChild("FloatVelocity"):Destroy()	
								end
								script.Parent.FlightLeft.Value = 0
							end			
							
							if landed then
								Flying = false
								Float = false
								DB = true
								script.Wind:Stop()
								FlyAnim:Stop()		
								VelVal.Value = 1	
								if character.HumanoidRootPart:FindFirstChild("FloatVelocity") then
									character.HumanoidRootPart:FindFirstChild("FloatVelocity"):Destroy()	
								end
								script.Parent.FlightLeft.Value = 0
							end										
							
							if script.Parent.FlightLeft.Value < 100 and Flying == false then
								Flying = false
								Float = false
								DB = true
								script.Wind:Stop()
								FlyAnim:Stop()		
								VelVal.Value = 1	
								if character.HumanoidRootPart:FindFirstChild("FloatVelocity") then
									character.HumanoidRootPart:FindFirstChild("FloatVelocity"):Destroy()	
								end
								script.Parent.FlightLeft.Value = 0
							end

							if stamdb then
								return
							end
							stamdb = true
							wait(0.05)
							stamdb = false
							if script.Parent.FlightLeft.Value > 0 then
								script.Parent.FlightLeft.Value -= 1
							end
						end
					end)
				end

			elseif not FlyAttemp then
				DB = false
			end
		elseif DB == true then 
			DB = false
			Flying = false
			Float = false
		end
	end
end)
4 Likes

im a new lua learn so dont hate me, i would recomend like example: if player is on air = true then(do a smooth of remove velocity)
and if player fall like if player falling = true then (make a smooth add of velocity but faster)

1 Like

well the player is techically always falling as it’s in the air, but this is old code i’ve had for a while and i just wanted to see if anyone could help me get it to work better with the losing speed, right now you can slightly fly upwards a little to gain speed and not lose it

1 Like

but you can make for check if is falling when the player stop pressing the button for fly

that’s not what i’m looking for, i’m looking to make it so when you look upwards you lose speed fast but if you look down you gain speed, sorry for the confusion

Utilize the players lookvector and then add/remove speed based on an established ground point (angles).

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.