Step 2 – SellScript

SellScript

In this game, a player will get 100 Gold for each item. After getting money, their items will be set back to 0, letting players explore the world for more items.

Start on line 1.

Create and Set Up the sellItems() Function

  1. Under local sellPart = script.Parent, create a function named sellItems that gets two parameters named playerItems and playerMoney.
  2. To give players the right amount of gold, take the value of the playerItems and multiply it by the amount of gold they should receive per item. This example gives one hundred gold pieces per item. In the sellItems function, type the following: local totalSell = playerItems.Value * 100
  3. Type playerMoney.Value = playerMoney.Value + totalSell to add the gold for the items to their current gold.
  4. Type playerItems.Value = 0. This sets a player’s items back to 0. If a player’s items aren’t set back to 0, the script will keep giving players gold without stopping.

Now that the sellItems function is created, it can be called in onTouch to give whatever player touches sellPart.

Playtesting

Playtest your game and collect some of your items. Walk on the SellPlatform and make sure you get Gold and your items disappear from your leaderboard.