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

How can i make a player's character jump using a key pressed event?

Hey, i was following a video tutorial from peas factory about key pressed event. I followed everything he did in that video and i wanted to test myself by trying something new. I wanted my character to jump when a key was pressed but i don't really know how to do it. I also looked up the roblox wiki page and i found out that Humanoid.Jump is a bool value, so if i want my character to jump i must set it to true. I was wondering if someone could help me with my script.

player  = game.Players.LocalPlayer
tool = script.Parent
handle = tool.Handle
tool.Equipped:Connect(function(mouse)
	mouse.KeyDown:connect(function(key)
		if key == "f" then
			player.Character.Humanoid.Jump = true
		end
	end)
end)

Also i inserted a tool in the starter pack,a part called "Handle" in the tool and the script i used was a local script so there are no tehnical issues to call them this way.

Thanks in advance for helping me!

5 comments

0

Did you test the script? If it didn't work, were there any errors?

0

there were no errors and yes i tested it

0

KeyDown is deprecated, use User input service: https://developer.roblox.com/en-us/api-reference/class/UserInputService Message me if you need help

0

Also, im writing a script for you.

0

thanks in advance

1 answer

✓ Accepted answer

Are you sure that tool.Equipped:Connect(function(mouse) the tool.Equipped event will return your player’s mouse?

here’s a solution remove the mouse, then add a new variable named

local mouse = player:GetMouse()

under the player variable, also using global variables are generally bad habits in Lua, you want to local every variable, for speed and performance bonuses

3 comments

0

i'll test this out in a minute,thanks in advance

0

i tested "tool.Equipped:connect" by changing my cursor and it worked. Also i made all the variable local and tested the code with the variable you told me to and i found out that that the problem was at this line: "player.Character.Humanoid.Jump = false"

0

this is what i see in the output: " 18:53:10.585 - Humanoid is not a valid member of Player" could you help me fix that line?

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