Dialog Shop Tutorial

This is an easy tutorial This is an easy tutorial. This tutorial discusses scripting. Return to tutorial index


Dialog shops are easy to create and can be made to sell many different items, such as weapons, cars, or upgrades. They can also be used in a wide range of games from adventure games to RPGs. In this tutorial will be going over how to make a weapons shop.

What's First?[edit]

As the shop is going to sell weapons, we will need to select at least one weapon to sell in the shop. There are some great weapons in the "Tools & Weapons" category of the toolbox.

Now that we have a weapon we can get started. The weapon(s) should be located in the Workspace, and we need put any weapons into ReplicatedStorage. Rename the weapon to "Weapon1", and if there is more than one weapon, name them like so: "Weapon1", "Weapon2", etc. At this point the ReplicatedStorage should look something like this (if there is more than one weapon, it will look slightly different):


  • Expand.png
    ReplicatedStorage
    ReplicatedStorage
    • Expand.png
      Model
      Weapon1


Making The Shop[edit]

The Seller

In a shop there is always someone behind the counter ready to help you, and we now need to make this person. This seller can be as creative as you want her to be; for this tutorial I will be using a basic Part inside a Model. We now need to insert a Dialog into the seller, make sure that the part you insert it into is named "Head". Next we will need to insert a Humanoid into the Model of the seller.

To insert a Dialog go to Insert -> Object -> Dialog.

The Shop

Now that we have the seller set up and ready to sell some weapons, we need to make the actual shop. To make the shop we will use DialogChoice and ResponseDialog to ask questions and give answers.

To start, select the Dialog that was created and in the properties window change the Purpose value to "Shop". In the properties window again change the InitialPrompt value to whatever the shop keeper should say when the player interacts with her, I will be using "Welcome to my shop!".

Next we will add the options the shopper can choose to ask the seller, we will do this by inserting a DialogChoice into the Dialog. To insert a DialogChoice go to

Insert -> Object - > DialogChoice.

In the properties window change the UserDialog value to "May I browse your goods?" and the ResponseDialog value to "Sure!".

Note: Any of the above text in quotations can be changed, it does not affect the shop.

Next we will need to Insert some more DialogChoices into the DialogChoice we just made, insert as many DialogChoices as you do weapons. Rename them from "ChoiceA" to whatever amount of weapons you are selling, so if there were three weapons they would go from "ChoiceA" to "ChoiceC".

The Dialog should now look something like this:

  • Expand.png
    Workspace
    Workspace
    • Tree-collapse.png
      Model
      NPC
      • Tree-collapse.png
        Part
        Head
        • Tree-collapse.png
          Dialog
          Dialog
          • Tree-collapse.png
            DialogChoice
            DialogChoice
            • DialogChoice
              ChoiceA
            • DialogChoice
              ChoiceB
            • DialogChoice
              ChoiceC
      • Humanoid
        Humanoid
  • Expand.png
    ReplicatedStorage
    ReplicatedStorage
    • Expand.png
      Model
      Weapon1
    • Expand.png
      Model
      Weapon2
    • Expand.png
      Model
      Weapon3


Make The Shop Do Stuff[edit]

To make the shop work we will need to insert a Script into the Dialog inside the seller's head. Inside the script copy the following code:

Note: The code below uses a Leaderboard.

Select
local dialog = script.Parent
dialog.DialogChoiceSelected:connect(function(player, choice)
    -- Check the player has a stats object
    local stats = player:FindFirstChild('leaderstats')
    if not stats then return end
 
    -- And that the stats object contains a gold member
    local gold = stats:FindFirstChild('Gold')
    if not gold then return end
 
    if choice == script.Parent.DialogChoice.ChoiceA then
        if gold.Value >= 5 then -- 5 is the amount of gold you need to purchase this weapon
            game.ReplicatedStorage.Weapon1:Clone().Parent = player.Backpack
            gold.Value = gold.Value - 5 -- subtract the amount of gold you need to purchase
        end
    elseif choice == dialog.DialogChoice.ChoiceB then
        if gold.Value >= 10 then
            game.ReplicatedStorage.Weapon2:Clone().Parent = player.Backpack
            gold.Value = gold.Value - 10
        end
    elseif choice == dialog.DialogChoice.ChoiceC then
        if gold.Value >= 15 then
            game.ReplicatedStorage.Weapon3:Clone().Parent = player.Backpack
            gold.Value = gold.Value - 15
        end
    end
end)