I've got this bit of code that activates a bodythrust and some sparkles in the player's character whenever they press F. I only want the player to be able to press F once while they're in the air. It'd be even better if they could'nt use it on the ground. How can I make this happen?
Here's the code.
thrust = Player.Character.HumanoidRootPart:FindFirstChild("BodyThrust") sparkles = Player.Character.HumanoidRootPart:FindFirstChild("Sparkles") MyMouse.KeyDown:connect(function(key) if (key:byte() == 102) then thrust.Force = Vector3.new(0,3000,-10000) sparkles.Enabled = true wait(0.25) thrust.Force = Vector3.new(0,0,0) sparkles.Enabled = false end end)
So you need to use humanoid:GetState(), as theking was saying, and you need to get the current state of the humanoid. An example of how this works . . .
humanoid.Changed:Connect(function() if humanoid:GetState() == Enum.HumanoidStateType.Landed then print("Player has landed.") end end)
For a list of the different state types: https://developer.roblox.com/api-reference/enum/HumanoidStateType
So with yours, I might do something like . . .
local humanoid = Player.Character:WaitForChild("Humanoid") MyMouse.KeyDown:Connect(function(key) if (key:byte() == 102) then if humanoid:GetState() ~= Enum.HumanoidStateType.Landed and humanoid:GetState() ~= Enum.HumanoidStateType.None -- Checks if the humanoid's state isn't either landed or none. -- Rest of script here: end end end)