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

How would I make it so that the player can only use this boost once for every time they go airborne?

Asked by 5 years ago

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)
0
try using the GetState ( ) function of humanoid theking48989987 2147 — 5y
0
That is how you would do it, but not very descriptive. Knineteen19 307 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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)
0
thank you NEXIUS10 13 — 5y
0
Glad I helped! Knineteen19 307 — 5y
Ad

Answer this question