Hello, if you are reading this I am making a progressive shop system so you have to unlock one item to unlock the next item and so on. But I am encountering some errors in the process.
Heres what the gui looks like in game so once u buy the first item then it will show the next one:
Heres my scripts so far:
local player = game.Players.LocalPlayer
local leaderstats = player:WaitForChild(“leaderstats”)
local coins = leaderstats:WaitForChild(“Coins”) – Assuming “Coins” is the currency for purchases
local swords = { – Table with sword prices and respective sword names
{name = “Sword2”, price = 100},
{name = “Sword3”, price = 200},
{name = “Sword4”, price = 300},
{name = “Sword5”, price = 400}
}
– GUI Elements
local shopFrame = script.Parent.Frame
local swordButtons = { – Sword image buttons and buy buttons
{image = shopFrame:WaitForChild(“Sword1Image”), buyButton = shopFrame:WaitForChild(“BuyButton1”)},
{image = shopFrame:WaitForChild(“Sword2Image”), buyButton = shopFrame:WaitForChild(“BuyButton2”)},
{image = shopFrame:WaitForChild(“Sword3Image”), buyButton = shopFrame:WaitForChild(“BuyButton3”)},
{image = shopFrame:WaitForChild(“Sword4Image”), buyButton = shopFrame:WaitForChild(“BuyButton4”)}
}
– This function checks what swords the player owns and updates the shop UI accordingly
local function updateShop()
for i, swordInfo in ipairs(swords) do
local hasSword = player.Backpack:FindFirstChild(swordInfo.name) or player.StarterGear:FindFirstChild(swordInfo.name)
swordButtons[i].image.Visible = hasSword or i == 1 or player.Backpack:FindFirstChild(swords[i-1].name)
swordButtons[i].buyButton.Visible = not hasSword and (i == 1 or player.Backpack:FindFirstChild(swords[i-1].name))
end
end
– This function handles purchasing the sword
local function purchaseSword(swordIndex)
local swordData = swords[swordIndex]
if coins.Value >= swordData.price then
coins.Value = coins.Value - swordData.price
local newSword = game.ReplicatedStorage:FindFirstChild(swordData.name):Clone() – Assumes swords are stored in ReplicatedStorage
newSword.Parent = player.Backpack
newSword.Parent = player.StarterGear
updateShop() – Refresh the shop UI after purchase
else
print(“Not enough coins!”)
end
end
– Connect the buttons to purchase the corresponding swords
for i, buttonInfo in ipairs(swordButtons) do
buttonInfo.buyButton.MouseButton1Click:Connect(function()
purchaseSword(i)
end)
end
– Initial UI update
updateShop()
Heres my coins script:
game.Players.PlayerAdded:Connect(function(p)
local stats = Instance.new(“IntValue”)
stats.Name = “leaderstats”
stats.Parent = p
local money = Instance.new("IntValue", stats)
money.Name = "Coins"
money.Value = 999999999
end)
Heres my hiarchy for explorer:
(I also have my tools in replicated storage u can see that in the script tho.)