How do I make my dunk button work?

Hello Developers,

In my latest post you’ve seen i’ve been working on a Basketball Game. But I need a Dunk button. I made the GUI but my script isn’t working. I don’t really want the dunk complicated, I’m just trying to make it that if you click the button it makes you jump in the air high so that they can reach the hoop. I could use some help, Thank you.

3 Likes

Could you show us the script please so we can help?

My old script is a bit of a failure at the moment. Because my cousin (the person who originally made the script) is a animation type of guy, and he made it like you but the animation id in for a good dunk. I cannot animate that good so I need to learn how I get the script to make the jump higher, if you know how.

Hey! I think I might be able to help.

First of all, I assume you already have a “target” part in your basketball game but if you don’t, do something like this:


Here I simply positioned a no collide, invisible 1x1 part above the center of the rim.

From there, you are going to need to use a BodyPosition to move them up towards the hoop and a BodyGyro to make them face the hoop. I can provide a small code snippet of how I did it in my game:

local dist = (hrp.Position - target.Position).magnitude -- get the distance from the hoop

local gyro = Instance.new("BodyGyro")
gyro.CFrame = CFrame.lookAt(hrp.Position,Vector3.new(target.Position.X,hrp.Position.Y,target.Position.Z))
gyro.MaxTorque = Vector3.new(math.huge,math.huge,math.huge)
gyro.P = 75000
gyro.Parent = hrp
-- Essentially, create a gyro that faces the player at the hoop. We only want to rotate them on the y-axis, as any other axis will make them rotate up/down etc

local pos = Instance.new("BodyPosition")
pos.D = 1100
pos.P = 15000

local goalPosition = (CFrame.new(target.Position, Vector3.new(hrp.Position.X, target.Position.Y, hrp.Position.Z)) * CFrame.new(0, -1, -3)).p

pos.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
pos.Position = goalPosition

pos.Parent = hrp

-- play a dunk animation if you want.

-- Creates the main part that actually moves the player. 
-- We simply multiply the goal position we want by -1 and -3 to offset it so they won't fly into the rim directly.

From here, you would want to connect this with a button press (like spacebar) or a gui button press. Hopefully this helped! Good luck w/ your game.

5 Likes

SpacePuppy2 has a good idea I suggest you learn from his idea. Good luck with your game!

2 Likes

I have something that’s like that, it’s a small brick that if the basketball hits it, it makes a billboard GUI that says “SCORE!” I don’t really understand, but I’m going to try to do something like that. Thanks.

2 Likes