Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I check if the player is in mid-air?

Hey. I want to make a script that runs an animation and plays a sound only when the player is in Air. How can I do it? This is what I have so far:

player = game.Players.LocalPlayer
mouse = player:GetMouse()

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

local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/Asset?ID=2161945388"

local animTrack = Humanoid:LoadAnimation(animation)

local GlideSound = Instance.new("Sound", workspace)
GlideSound.SoundId = "http://www.roblox.com/Asset?ID=1000941579"

function onKeyPress(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == Enum.KeyCode.R then
		print("R was pressed")
		animTrack:Play()
		GlideSound:Play()
	end
end

game:GetService("UserInputService").InputBegan:connect(onKeyPress)

2 comments

2

https://wiki.roblox.com/index.php?title=API:Enum/HumanoidStateType Use this to check if the player is in the Jumping or Freefall State, or just Freefall if you want it to be when they are falling

0

Can someone check the HealthBar question?

1 answer

✓ Accepted answer

As CPF2 suggested, you are able to check the HumanoidStateType to see if they are freefalling. However, in order to tell when their state type changes, you can use StateChanged. The list of states you can check for are found here, and the one you will want to use is Freefall. For example, you could do something like this to tell when the player enters freefall mode:

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()

char:WaitForChild("Humanoid").StateChanged:Connect(function(OldState,NewState)
	if NewState == Enum.HumanoidStateType.Freefall then
		--play sound and animation
	else
		--end sound and animation
	end
end)

Hope this helps!

1 comment

0

Indeed it did :D Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.