How can I make this change a gravity only when the player is already in the air?

I’ve started working on this sorta rayman type game and started to work on the gliding ability. My problem is when instead of only changing the gravity when the player is already in the air, it changes it after the second jump.

Anyway I can fix it to the way I want?

userinput = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local C = player.Character
local human = C.Humanoid

human.Jumping:Connect(function(IsJumping: boolean)
	if IsJumping then
		userinput.InputBegan:Connect(function(input, gameProcessed)
			if input.KeyCode == Enum.KeyCode.Space then
				workspace.Gravity = 25
				end
			end
		end)
	end
end)```

It is very easy. It uses the humanoid event called StateChanged.

local player = game.Players.LocalPlayer
local C = player.Character
local human = C.Humanoid



human.StateChanged:Connect(function(oldState, newState) --Check state
	if newState == Enum.HumanoidStateType.Freefall then
		workspace.Gravity = 25
	elseif oldState == Enum.HumanoidStateType.Freefall and newState ~= Enum.HumanoidStateType.Freefall then
		workspace.Gravity = 196.2
	end
end)

This seems, to just make the humanoid just have low gravity the entire time (and jump really high for some reason). I mean’t to have it more like a double jump type of thing but, I’ll see what I can do with this. I get if my question was confusing for what I was asking for.

A double jumping system? I have no clue to make one so I am gonna try. Let you know when I make one that works.

2 Likes

Made it without any help.

local C = script.Parent
local human = C.Humanoid
local UserInputService = game:GetService("UserInputService")
local connection


human.StateChanged:Connect(function(oldState, newState) --Check state
	if newState == Enum.HumanoidStateType.Freefall then
		workspace.Gravity = 60
		connection = UserInputService.InputBegan:Connect(function(key)
			if key.KeyCode == Enum.KeyCode.Space then
				C.HumanoidRootPart.Velocity = Vector3.new(0,50,0)
				connection:Disconnect()
				connection = nil
			end
		end)
	elseif oldState == Enum.HumanoidStateType.Freefall and newState ~= Enum.HumanoidStateType.Freefall then
		workspace.Gravity = 196.2
		if connection then
			connection:Disconnect()
			connection = nil
		end
	end
end)
2 Likes

Setting the NewState gravity to 10 and Y Velocity to 5 makes it work exactly I want it to