When a user presses a certain key on the keyboard a frame will move up in a jumping motion and fall back down.
I added a cool down and a debounce
These three variables control the bounce method.
I don't know what's wrong with it, but this is my attempt at a jump event.
function Bounce(gui)
What do I need to do to fix this? Am I doing anything wrong? I checked the parents too.
local JumpHeight = 0.05 local JumpDuration = 0.5 local JumpCooldown = 1
local box = script.Parent.Box --Jump function keyDown(key) if key == "z" then local Jumpable = true function Bounce(gui) if not Jumpable then return end Jumpable = false local JumpHeight = 0.05 local JumpDuration = 0.5 local JumpCooldown = 1 box:TweenPosition(UDim2.new(gui.Position.X.Offset,gui.Position.X.Scale,gui.Position.Y.Offset,gui.Position.Y.Scale+JumpHeight),"Out","Quad",.5) wait(JumpDuration) box:TweenPosition(UDim2.new(gui.Position.X.Offset,gui.Position.X.Scale,gui.Position.Y.Offset,gui.Position.Y.Scale-JumpHeight),"Out","Quad",.5) wait(JumpCooldown) Jumpable = true end end end
First, if the variable Jumpable
is your debounce, you put it in the wrong scope. Whenever the user presses 'z' a new debounce would be created, meaning no matter what when the user presses 'z', they will jump. Place that line right under local JumpCooldown = 1
.
Second, you create the function Bounce(gui)
but never call to it. Whenever the user presses 'z', you are creating a new function that is never called or executed. I suggest getting rid of that whole line (function Bounce(gui)
) and one of the ends on lines 20-22.
If you do that and move the local Jumpable = true
line to where I suggested, then you should be good to go as far as I can see.