How to make a working trampoline

At the end of this tutorial you will be able to create something like this:
robloxapp-20211023-2121147.wmv (731.9 KB)

Also read these terms

  • Humanoid.JumpHeight = The height in studs, which the player can jump, example if keep this 100 studs, I will jump in the game I can jump 100 studs
  • Humanoid.Jump = Each time player jumps, this will become true, then after 1 second false, this is a bool value, it means true/false value
  • Humanoid = This is the main object in player’s character and its not a BasePart/Mesh/Model
    So its just 2 steps

Tutorial

Step 1

Make a part, keep it in game.Workspace

Step 2

Add a script,
Check the script below

local canwork = true -- to avoid loops
local prevjumpheight = 0 -- this is to get back the player height to the height which was before jumping on trampoline

script.Parent.Touched:Connect(function(hit) -- event fires when some thing touches the trampoline
    if hit.Parent:FindFirstChild("Humanoid") and canwork == true then -- if its a player who stepped
        local humanoid = hit.Parent:FindFirstChild("Humanoid")
        canwork = false -- now script wont run
        prevjumpheight = hit.Parent:FindFirstChild("Humanoid").JumpHeight
        humanoid.JumpHeight = 150 -- this is the height that the player can jump, we make it 150, so the player can jump high
        humanoid.Jump = true -- we will make the player jump, so its like a trampoline
        task.wait(2) -- when the player goes up the sky by 150 studs, we make the player height they can jump normal
        humanoidd.JumpHeight = prevjumpheight -- again the player character jump height in studs become normal
        canwork = true -- script runs again
    end
end)

Step 3:

Enjoy! Tutorial is done

How this works:

This is a working trampoline, not a glitchy ones like in many games, this works good and does not look glitchy

3 Likes

Can you please explain how the script works? It seems to be a tutorial, not a script dump.

Explanations can help beginning scripters to learn how code works, and allows them to let their programming knowledge grow.

8 Likes

I know that this is tutorial but here are some suggestions from me.

  1. Don’t repeat hit.Parent:FindFirstChild("Humanoid") instead create a variable for it.
  2. You shouldn’t use wait() as its probably gonna be deprecated, and there is already replacement for it which is task.wait().
  3. You could optionally avoid nesting the if statement but that’s a personal preference.
  4. Your prevjumpheight variable is not in use and its only being set but not read, and it doesn’t have to be a global variable.
local jumpPart = script.Parent
local jumpHeight = 150
local debounce = true

jumpPart.Touched:Connect(function(hit)
	if not debounce then return end
	
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	if not humanoid then return end
	
	debounce = false
	
	local previousJumpHeight = humanoid.JumpHeight
	
	humanoid.JumpHeight = jumpHeight
	humanoid.Jump = true
	task.wait(2)
	humanoid.JumpHeight = previousJumpHeight
	
	debounce = true
end)
6 Likes

bruh when and why is wait() deprecating I need to change alot of scripts in my game like 50+

You don’t have to, its gonna retain its functionality and it will not be deprecated anytime soon, but what it really means is that for the future scripts/projects you should use task.wait() and other methods such as task.delay(), task.spawn() and etc.

If you keep wait, if some other player steps between the waiting time, its not counted, just test my script

You will know that it works because I tested it right now

Oops wrong chat, sorry

Ok I understood your reply :wink:

1 Like

This is exactly how the trampoline works in older games, and I can see you’re using FindFirstChild a lot and Wait (and not task.wait)

And from what I can see, prevjumpheigjt is not used anywhere.

I recommend you learn more things and remake the script entirely.

2 Likes