Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How could I make a shop usable?

Asked by 2 years ago

So I have been making a shop for my game, and when you press the buy button, it gives you the item, but when you press the button on a different item, it doesn't give you the item, but still charges you for the item. I think it's that the game saves the variable and when you buy a different item, it gives you the first one. Also, this game's inventory is only supposed to have one item at a time, so the item gets replaced instead of added to the inventory. Here's the code:

BuyButton Script:

01local img = script.Parent.ItemImage
02local cost = script.Parent.ToolCost
03local name = script.Parent.ToolName
04local desc = script.Parent.Description
05local buy = script.Parent.Buy
06 
07local replicatedStorage = game:GetService("ReplicatedStorage")
08local tools = replicatedStorage:WaitForChild("Tools")
09local buyTool = replicatedStorage:WaitForChild("BuyTool")
10 
11local mainShop = script.Parent:WaitForChild("MainShop")
12local template = mainShop:WaitForChild("Template")
13 
14function GetChildrenAlphabetical(instance)
15    local children = instance:GetChildren()
View all 65 lines...

GiveItem Script:

01game.ReplicatedStorage.BuyTool.OnServerInvoke = function(player, item, cost)
02    if game.ReplicatedStorage.Tools:FindFirstChild(item.Name) and item:FindFirstChild("Cost") then
03        if player.leaderstats.blinds.Value >= item.Cost.Value then
04            local tool = game.ReplicatedStorage.Tools[item.Name]:Clone()
05            player.Backpack:ClearAllChildren()
06            player.StarterGear:ClearAllChildren()
07            tool.Parent = player.Backpack
08 
09            local starterTool = tool:Clone()
10            starterTool.Parent = player.StarterGear
11 
12            player.leaderstats.blinds.Value = player.leaderstats.blinds.Value - cost.Value
13 
14            return "BoughtItem"
15        else
View all 21 lines...

If someone could give me an answer, that would be great. Thanks!

Answer this question