How do I change keydown to keypress when jumping?

So I think I got this right, I want keypress not keydown for spacebar when the player jumps. I don’t want the player to be able to hold the spacebar doing to do jumps, they can only do it on each press of the spacebar instead. I cannot find any information in the docs on keydown and keypress though so even any direction on that would be helpful? My main question is not of writing the script but more where is this in the documentation so I can work it out from there?

1 Like

here and put it into startercharacterscripts

script:

local canjump = true

wait(2)

if script.Parent.ClassName == “Model” then

local character = script.Parent
print(character.Name)
character.Humanoid.UseJumpPower = true
character.Humanoid.JumpPower = 0
local function jump()
	if canjump == true then
		canjump = false
		character.Humanoid.Jump = true
		character.Humanoid.JumpPower = 50		
		wait(0.05)
		character.Humanoid.JumpPower = 0
		wait(3)
		canjump = true

	end

end
	character.Humanoid:GetPropertyChangedSignal("Jump"):Connect(jump)

end

1 Like

i tested it and it worked. i hope it helped

1 Like

The player module is a module that automatically replicates and instantiates when you have load character enabled equal to true in the workplace settings. Within this module and its children you will find the necessary code to change, the default character controller logic!

1 Like

I had a similar script in mind, but I thought there might be something in the API to simply switch between keypress and keydown? I guess not if this seems the most likely way to do it and theres nothing documented which I can find. Because then you could simply disable keydown in some way rather than relying on a timer, which in my opinion would be a quicker more efficient way to do it perhaps? I come from Unity game engine it can be hard to adapt like this sometimes lol. Thanks for the help I am just going to use a script like this!

1 Like

Many thanks I will give this a look!

yay my first Solution ever :smiley: yay

2 Likes

I changed the code formatting a bit just thought I would update

local canjump = true
wait(2)
if script.Parent.ClassName == "Model" then

	local character = script.Parent
	print(character.Name)
	character.Humanoid.UseJumpPower = true
	character.Humanoid.JumpPower = 0
	local function jump()
		if canjump == true then
			canjump = false
			character.Humanoid.Jump = true
			character.Humanoid.JumpPower = 50		
			wait(0.05)
			character.Humanoid.JumpPower = 0
			wait(3)
			canjump = true
		end
	end
	character.Humanoid:GetPropertyChangedSignal("Jump"):Connect(jump)
end