Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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
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 CPF2 406 — 5y
0
Can someone check the HealthBar question? thefatrat87 18 — 5y

1 answer

Log in to vote
1
Answered by
mattscy 3725 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

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!

0
Indeed it did :D Thanks! bruceywayne 35 — 5y
Ad

Answer this question