PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience

Creating Harvestable Items

Creating Harvestable Items

Prerequisites
  • General knowledge of Studio covered in Intro to Studio
  • Knowledge of scripting covered in Coding 2
  • Students should have completed Adventure Game - Leaderboards
  • Lesson Time 10 - 20 minutes
    Optional Handouts
  • Game Vision Document
  • Learning Objectives
  • Understand how to organize parts with Models and Unions
  • Learn how to use a BoolValue (Boolean) to keep track if an object has been harvested or not
  • The players also need items, like cupcakes or trees, to harvest and sell for gold.

    Build With Parts, not with the Toolbox

    It’s recommended that students build their items using parts in Roblox Studio and not from the Toolbox. Building with parts ensures the code in this course works as intended and helps students feel more ownership over their personalized projects.


    Build an Item

    1. In the Workspace, create a new Model named for the type of item players will collect. Refer back to your game vision document. In this game example, players harvest cupcakes.
    Using Models to Organize Parts

    Using a model is one way of keeping objects with parts and scripts organized. Models can be moved just like any other part using the Move tool.


    1. In Model, add parts to build the item players will harvest.
    1. Hold-down Ctrl and click on the parts of your cupcake.
    1. In the Model Tab, click Union. This combines your parts into one, which is required by the scripts you’ll make. It also makes it easier to organize your work to have one part rather than many.
    • You can only use union on basic parts like blocks, spheres, wedges, or cylinders.
    • If you get an error saying: "Union Failed, Triangle limit exceeded", try using fewer parts.If you don’t like the result of a union, undo it by selecting the unioned part and clicking Separate.
    • A unioned or negated part can only be scaled uniformly . If you need to change the size of a unioned part in a specific direction, it may be easier to undo the union, resize, and then redo the union.

    1. Make sure the unioned part has Anchoring turned on. If the part is not unioned and anchored, you’ll get issues during scripting

    Anchoring on

    Anchoring off

    Make Items Harvestable

    Players will harvest items by touching them with the tool. But when playing, the tool will also touch lots of things that shouldn’t be harvested, like walls and props. You don’t want players to get points for those.

    To set harvestable items apart from non-harvestable item, add a BoolValue object named CanHarvest. BoolValue objects store boolean values, which can be set to true or false. Whenever the script touches something, it’ll check for an object named CanHarvest. If the boolean value is true, the object will be harvested.

    Why Use a BoolValue Object?

    Another way of checking if an item can be harvested would be to code an if statement to check if it’s a Cupcake. To add more items to the game, like muffins or carrots, you’d have to add more if statements. Instead of all that extra code, just put a BoolValue object inside anything that you want to make harvestable.


    1. Under the Cupcake model, create a BoolValue object named CanHarvest.
    1. In Properties for CanHarvest, check the Value box. Checking the value box makes the boolean true, meaning players can harvest that item.

    These documents are licensed by Roblox Corporation under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. Roblox, Powering Imagination, and Robux are trademarks of Roblox Corporation, registered in the United States and other countries.