Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

7 comments

0

Explain dude.

0

It's not working because it's not indented properly

0

the indention is wrong. for sure.

0

If the player is jumping, they will be able to press space, how do I do that?

0

Also, indentation is optional, I don't really mind about it

1

well ur dumb then. roblox automatically indents by default, so its more work not to do it at all

0

I'm just a beginner, I add my function 1 by 1 to add new stuff that I learnt

1 answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.