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

How to detect if a player is jumping and is pressing a key after they jump?

Asked by 5 years ago

I'm trying to make this thing that when the player is jumping, they will be able to press space again to transform their character. Is there anything wrong with my script? the transform part is working, it's just when the player is jumping and is pressing the spacebar again.

if Humanoid.Jump == true then
game:GetService("UserInputService").InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.Space then
for _, child in pairs(script.Parent:GetChildren()) do
is_transformed = true
if child:IsA("UnionOperation") then
child.CanCollide = false
child.Transparency = 1
Animator.Parent = nil
Humanoid.HipHeight = 1
end
end
end
end)
end
0
Explain dude. greatneil80 2647 — 5y
0
It's not working because it's not indented properly User#24403 69 — 5y
0
the indention is wrong. for sure. DinozCreates 1070 — 5y
0
If the player is jumping, they will be able to press space, how do I do that? MArzalAlBuchariZ 33 — 5y
View all comments (3 more)
0
Also, indentation is optional, I don't really mind about it MArzalAlBuchariZ 33 — 5y
1
well ur dumb then. roblox automatically indents by default, so its more work not to do it at all Gey4Jesus69 2705 — 5y
0
I'm just a beginner, I add my function 1 by 1 to add new stuff that I learnt MArzalAlBuchariZ 33 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Here should be a way to do this:

local InputEvent
local LandingEvent
Humanoid.Jumping:Connect(function()
    local didSecondSpace = false
        if InputEvent ~= nil then
        InputEvent:Disconnect()
        end
        if LandingEvent ~= nil then
        LandingEvent:Disconnect()
        end
    InputEvent = game:GetService("UserInputService").InputBegan:Connect(function(input);
        if input.KeyCode == Enum.KeyCode.Space and didSecondSpace == false then
            didSecondSpace = true
            InputEvent:Disconnect()
            LandingEvent:Disconnect()
            for _, child in pairs(script.Parent:GetChildren()) do
                is_transformed = true
                if child:IsA("UnionOperation") then
                    child.CanCollide = false
                    child.Transparency = 1
                    Animator.Parent = nil
                    Humanoid.HipHeight = 1
                end
            end

        end
    end)
    LandingEvent = Humanoid.StateChanged:Connect(function(old, new)
        if new == Enum.HumanoidStateType.Landed and didSecondSpace == false then
            InputEvent:Disconnect()
            LandingEvent:Disconnect()
        end
    end)

end

I just free-handed it, didn't test it. So uh, yeah.

Ad

Answer this question