Getting when the player is on air

Hello Developers!
I am trying to make a combat system similar to “The Strongest Battlegrounds”
Everything was going good until I came across the downslam.

	elseif  input.UserInputType == Enum.UserInputType.MouseButton1 and UIS:IsKeyDown("Space") and count == 3 and Enum.Material.Air then
			
			print("Down")
		
		end
	end

I am basically making that if the combo is 3 and the player is holding space and if the game detects player is on air then the downslam fires however, it seems that I am not making it the correct way, anyone knows how to?

1 Like

You have to compare Humanoid.FloorMaterial == Enum.Material.Air

The humanoid being inside of the character

Thanks for taking the time of responding but this still does not work.

local Player = game.Players.LocalPlayer
local character = Player.Character
local humanoid = character.Humanoid

local UIS = game:GetService("UserInputService")

local debounce = false
local cd = .25

local currTime = 0
local prevTime = 0
local count = 0

UIS.InputBegan:Connect(function(input, isTyping)
	if isTyping then
		return
	elseif input.UserInputType == Enum.UserInputType.MouseButton1 then
		local blocking = Player.Character.Blocking
		local stunned = Player.Character.Stunned
		if blocking.Value or stunned.Value == true then return end
		if debounce == false then
			debounce = true

			local Stunned = Player.Character.Stunned
			if Stunned.Value == true then return end

			currTime = tick()

			local passedTime = currTime - prevTime
			if passedTime < 1 then
				count = count + 1
				if count > 4 then
					count = 1
				end
			else
				count = 1
			end
			
			print(count)
			
			game.ReplicatedStorage.Event:FireServer(count)
			
		elseif input.UserInputType == Enum.UserInputType.MouseButton1 and UIS:IsKeyDown("Space") and count == 3 then
			if blocking.Value or stunned.Value == true then return end
			count = 4 
			print("Up")
			
		elseif input.UserInputType == Enum.UserInputType.MouseButton1 and UIS:IsKeyDown("Space") and count == 3 and humanoid.FloorMaterial == Enum.Material.Air then
			
			print("Down")
		
		end
	end
	
end)

game.ReplicatedStorage.Event.OnClientEvent:Connect(function()
	prevTime = currTime

	wait(cd)
	debounce = false
	
end)

if humanoid.FloorMaterial == Enum.Material.Air then
	print("Okkk")
end

This is my client code by the way.

maybe try humanoidstatetype.falling, or just research humanoidstatetypes

The problem is you are checking if the player is has pressed down on their left mousebutton. But at the same time, you are also checking if the player has pressed down on their space key. When the player presses space or any key on the keyboard for that matter, the property UserInputType’s Value changes to Keyboard. And when you press a mouse button, the UserInputType’s value changes to Mouse. Do you see the issue?

elseif input.UserInputType == Enum.UserInputType.MouseButton1 and UIS:IsKeyDown("Space") then 

To go a little more in depth, when UserInputService Receives an Input, it can receive both Keyboard and Mouse inputs. But it will only receive one input at time. That first input being the first key or button that gets pressed. Here’s some code to make it easier to understand:

UIS.InputBegan:Connect(function(Input, IsTyping)
    local InputType = Input.UserInputType

    if not IsTyping then
        if InputType == Enum.UserInputType.MouseButton1 then
            print('Clicked')
        elseif InputType == Enum.UserInputType.Keyboard then
            print('Pressed Key')
        end
    end
end)

Now, if i press both the space key on my keyboard and my left mouse button. It will print what registered first, so let’s say if i pressed the space key some few milliseconds before i pressed my left mouse button. Then it will print:
image

And vice versa.
So to fix this issue, you would have to do something like this:

local UIS = game:GetService("UserInputService")

local SpacePressed = false

UIS.InputBegan:Connect(function(Input, IsTyping)
    local InputType = Input.UserInputType
    
    if not IsTyping then
        if InputType == Enum.UserInputType.Keyboard then
            if Input.KeyCode == Enum.KeyCode.Space then
                SpacePressed = true
            else
                SpacePressed = false
            end
        elseif InputType == Enum.UserInputType.MouseButton1 and SpacePressed then
            print("Pressed Space: ".. tostring(SpacePressed), "InputType: ".. InputType.Name)
           
            SpacePressed = false
        end
    end
end)

This is a rather simple fix, but it’s a basic example of a possible solution for your problem. Keep in mind, this isn’t supposed to replace your entire code, the purpose of this code snippet is just to show how to check for two input presses “at once”.

If you have any questions or problems just reply and I’ll make sure to reply back. :)!

maybe use raycasts to detect the floor

local char = script.Parent

local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {char}

local ray  = workspace:Raycast(HRP.Position, -HRP.CFrame.UpVector * 4.5, params)