Coding Powers

The Humanoid

This is what Roblox refers to as your character. If you look at the Explorer when you press play, you will see that your Humanoid is part of two sections- the Workspace and Players. What we will focus on is the Workspace.

A Humanoid has four property types

  • Data: CameraOffset, ClassName, DisplayDistanceType, HealthDisplayDistance, HealthDisplayType, Name, and more…
  • Behavior:Archivable, BreakJointsOnDeath
  • Jump Settings: AutoJumpEnabled, JumpPower, UseJumpPower
  • Control: AutoRotate, FloorMaterial, Jump, MoveDirection, PlatformStand, SeatPart, Sit, TargetPoint, WalkToPart, WalkToPoint
  • Game: AutomaticScalingEnabled, Health, HipHeight, MaxHealth, MaxSlopeAngle, Walkspeed

For this activity, we will focus on the Jump Settings and Game Properties.

Also you will see that if you use the Explorer to open the Parts of a Humanoid, it looks like this:

Create a Coin

Using the Cylinder part, make a large green coin. Cylinders are normally skinny so you will have to scale it short and then widen. Anchor it in the air and make sure CanCollide is unchecked. CanCollide means you can run through to get the power up.

Adding the Script and Numbers

Right click the Part and add a Script. Rename it PowerUpScript. Right click the Part again and under “Find Object” look for Number Value. Add three of those to the Part and name them: PowerTime, JumpPowerAmount, SpeedPowerAmount. Rename the Part itself to PowerUp.

NumberValue lets you store a number inside an object. If you look at it’s properties, you will see Value starts at zero. You can use Scripts to access this number. Instead of changing variables in your Script, you can change the number in Properties and just access the NumberValue via Script.

So, let’s make PowerTime’s Value 30. JumpPowerAmount set to 150 and SpeedPowerAmount set to 150.

Defining Local Variables

Go into the PowerUpScript and type the following:

As you can see below, we use NumberValue to set our local Scripts without using numbers inside the code. Instead, you can change the number in Properties. This way if your character doesn’t jump high enough, you don’t need to search the code but just change in Properties.

The GivePowers Function

Here’s the Code you need to write:

PowerUp.Touched:Connect(GivePowers)

Try it out!

This is a bit more complicated than our past coding so watch the video below to understand what is happening-

QuizzesStatus