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)
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!