I am stuck: Progressive shop system

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:

Screenshot 2024-10-22 212023

(I also have my tools in replicated storage u can see that in the script tho.)

I’m confused? I get what you’re trying to achieve but what part of the script are you having problems with? The way you copied the script to this question makes it unreadable for me, and lets start by giving out what’s working and what’s not.

The buy button isnt working at all and im getting this error in output: Infinite yield possible on ‘Players.jamesonmonroe.PlayerGui.ShopGUI.Frame:WaitForChild(“BuyButton1”)’

Try not to use WaitForChild. Either it’s that or you got the name mixed up

got any alternatives to use instead of waitforchild?

if i’m correct and the button already exists in the game (it doesnt get added by a script afterwards), then u don’t need to use WaitForChild… at all
just use shopFrame.BuyButton1

this still doesn’t solve the issue of buybutton1 not existing… how does the current tree / hierarchy / parents and children look in shopframe?

Screenshot 2024-10-22 212023

This is it

So like this local shopFrame = script.Parent.Frame
local swordButtons = { – Sword image buttons and buy buttons
{image = shopFrame.Sword1Image, buyButton = shopFrame.BuyButton1},
{image = shopFrame.Sword2Image, buyButton = shopFrame.BuyButton2},
{image = shopFrame.Sword3Image, buyButton = shopFrame.BuyButton3},
{image = shopFrame.Sword4Image, buyButton = shopFrame.BuyButton4}
}

yeah i suppose
did you get it working?