Okay so I have made the script, but I am not sure how to make it take away a certain amount for each item and not let the player have the item if they don't have that amount of money. Here is the script:
script.Parent.DialogChoiceSelected:connect(function(player, choice) if choice == script.Parent.C then gunB = game.Lighting["Burger"]:clone() gunB.Parent = player.Backpack elseif choice == script.Parent.D then gunC = game.Lighting["Pizza"]:clone() gunC.Parent = player.Backpack elseif choice == script.Parent.E then gunC = game.Lighting["Ice"]:clone() gunC.Parent = player.Backpack elseif choice == script.Parent.F then gunC = game.Lighting["Cola"]:clone() gunC.Parent = player.Backpack end end)
For your shop, you will need to use Leaderboards. There's other ways to do that too, but it's better to do with that, as Roblox handles updating the player list.
Supposing you made yourself some Leaderboards and you put the money counter in as "Money", here's your finished script:
script.Parent.DialogChoiceSelected:connect(function(player, choice) if choice == script.Parent.C then if player:WaitForChild("leaderstats").Money.Value >= insertrequiredmoneyhereA then -- WaitForChild just in case player:WaitForChild("leaderstats").Money.Value == player:WaitForChild("leaderstats").Money.Value - insertrequiredmoneyhereA -- As paying for something needs money, we take off the required money from the player's wallet. --In addition, you can freely refer to the value which is going to be edited itself, as i did above. The value it finds at that moment gets used. gunB = game.Lighting["Burger"]:clone() gunB.Parent = player.Backpack else --Insert script on not enough money here. Unless you put script that gives the player the item in this space, no item will be given to the player if he doesn't reach insertrequiredmoneyhereA. end elseif choice == script.Parent.D then if player:WaitForChild("leaderstats").Money.Value >= insertrequiredmoneyhereB then player:WaitForChild("leaderstats").Money.Value == player:WaitForChild("leaderstats").Money.Value - insertrequiredmoneyhereB gunC = game.Lighting["Pizza"]:clone() gunC.Parent = player.Backpack else --Again, insert script on not enough money here end elseif choice == script.Parent.E then if player:WaitForChild("leaderstats").Money.Value >= insertrequiredmoneyhereC then player:WaitForChild("leaderstats").Money.Value == player:WaitForChild("leaderstats").Money.Value - insertrequiredmoneyhereC gunC = game.Lighting["Ice"]:clone() gunC.Parent = player.Backpack else --Insert script on not enough money here, once more end elseif choice == script.Parent.F then if player:WaitForChild("leaderstats").Money.Value >= insertrequiredmoneyhereC then player:WaitForChild("leaderstats").Money.Value == player:WaitForChild("leaderstats").Money.Value - insertrequiredmoneyhereC gunC = game.Lighting["Cola"]:clone() gunC.Parent = player.Backpack else --Finally, insert script on not enough money here. end end end) --By the way, did i tell you to insert script on not enough money here?!?!?!?!?!??!?!?!1one!??!?!?!eleven!?!?1one1111!
You need to index the Currency Statistic of the player's leaderstats. Once you do this then you can check if the value is greater than or equal to your specified price with the >=
operator.
The standard leaderboard setup goes like this;
Player
The 'leaderstats' value must be named 'leaderstats' and whatever values you put in there will be part of the leaderboard.
Name all the dialogchoices to correspond with the food they'll give!!
Make a table full of the items and their prices, you can then iterate through this table with a generic for
loop. You can then index the currency leaderstat, check if the player has enough, subtract the price from their leaderstat, then give them the object.
--lets make a table, this table will be full of the names of the food and their prices. local items = { ['Burger'] = 25, --A burger will be 25 currency. ['Pizza'] = 50, ['Ice'] = 75, ['Cola'] = 100 } script.Parent.DialogChoiceSelected:connect(function(player, choice) --Iterate through table for i,v in pairs(items) do --Check if it's the right choice if choice.Name == i then --Define the leaderstat. MAKE SURE 'CurrencyStat' IS THE CORRECT NAME. local stat = player.leaderstats.CurrencyStat --Check if they have enough if stat.Value >= v then --Give them the item. game.Lighting[i]:Clone().Parent = player.Backpack end end end end)