Jump Pad
Part of the Roblox Game Scripting section of Coddy's Lua journey. Lesson 19 of 25.
JumpHeight is how high a character jumps, in studs. The default is 7.2, about the height of a character.
Older games use JumpPower instead: the speed a character leaves the ground with. A new Roblox place ignores JumpPower unless UseJumpPower is turned on (in Studio: StarterPlayer, CharacterUseJumpPower), so when a JumpPower script from a tutorial does nothing, this is why. JumpHeight is the simpler one: the number is the height.
A power-up that lasts a while needs to undo itself later. task.delay(seconds, function) runs the function after that many seconds, without pausing the rest of your code:
humanoid.WalkSpeed = 30
task.delay(10, function()
humanoid.WalkSpeed = 16
end)
print("Boost on")Boost on prints at once; the speed goes back to 16 ten seconds later.
The pad only changes a property. The player still presses Space to jump.
Challenge
MediumMake the blue pad a jump pad, so players can reach the 14 stud ledge.
- Inside the
if, sethumanoid.JumpHeightto20. - 5 seconds later, set it back to
7.2withtask.delay.
Press Play, step on the pad, run at the ledge and jump: you land on top. Then Check.
Try it yourself
local pad = script.Parent
pad.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid then
-- 1. Let this player jump 20 studs high
-- 2. 5 seconds later, back to the normal 7.2
end
end)
All lessons in Roblox Game Scripting
2Loops and Functions
Row of PillarsStaircase BuilderTower BuilderCoin FactoryBlinking LightVanishing Bridge5Your First Game
Your First ObbyPractice on your own: Online Lua compiler