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

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

Asked by
seikkatsu 110
5 years ago

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!

0
Did you test the script? If it didn't work, were there any errors? itchymoonfire 179 — 5y
0
there were no errors and yes i tested it seikkatsu 110 — 5y
0
KeyDown is deprecated, use User input service: https://developer.roblox.com/en-us/api-reference/class/UserInputService Message me if you need help BashGuy10 384 — 5y
0
Also, im writing a script for you. BashGuy10 384 — 5y
0
thanks in advance seikkatsu 110 — 5y

1 answer

Log in to vote
0
Answered by
cegberry 432 Moderation Voter
5 years ago
Edited 5 years ago

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

0
i'll test this out in a minute,thanks in advance seikkatsu 110 — 5y
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" seikkatsu 110 — 5y
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? seikkatsu 110 — 5y
Ad

Answer this question