Speed Pad
Part of the Roblox Game Scripting section of Coddy's Lua journey. Lesson 18 of 25.
The Humanoid controls how a character moves. Two of its properties:
WalkSpeed: studs per second,16by defaultJumpHeight: how high the character jumps, in studs,7.2by default
Changing them on touch makes power-ups. This pad slows down anyone who steps on it:
local mud = script.Parent
mud.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid.WalkSpeed = 8
end
end)The change lasts until something sets the value again or the character respawns: a new character starts with the defaults.
Challenge
MediumMake the green pad a speed boost, so you reach the yellow line in under 2.2 seconds.
- Inside the Touched function, find the
Humanoidinhit.Parent. - If there is one, set its
WalkSpeedto50. A falling ball has no Humanoid and must cause no error.
Press Play and run over the pad: you speed off to the yellow line. Then Check.
Try it yourself
local pad = script.Parent
pad.Touched:Connect(function(hit)
-- Find the Humanoid and make it run at speed 50
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