Menu
CoddyTech

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, 16 by default
  • JumpHeight: how high the character jumps, in studs, 7.2 by 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 icon

Challenge

Medium

Make the green pad a speed boost, so you reach the yellow line in under 2.2 seconds.

  1. Inside the Touched function, find the Humanoid in hit.Parent.
  2. If there is one, set its WalkSpeed to 50. 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

Practice on your own: Online Lua compiler