I am making a tycoon game and am coding a dependancy system with attributes that locks buttons in a folder until a item is unlocked which then the button is put into the workspace. The system works fine at first but, when a second button was added, any button with a dependancy is unlocked when the first button is and the. Not only that but when i unlock the second button after unlocking the first one it reunlocks already unlocked buttons lastly said button just doesent work. Any help would be appriciated!
Purchase handling script:
local Purchases = script.Parent.Purchases:GetChildren()
local debounce = false
local TycoonFolder = Instance.new("Folder", game.ReplicatedStorage)
TycoonFolder.Name = script.Parent.Name
local LockedButtons = Instance.new("Folder", TycoonFolder)
local UsedButtons = Instance.new("Folder", TycoonFolder)
LockedButtons.Name = "LockedButtons"
UsedButtons.Name = "UsedButtons"
for _, purchases in pairs((script.Parent.Purchases:GetChildren())) do
purchases.Parent = game.ReplicatedStorage:FindFirstChild(script.Parent.Name)
purchases:GetAttribute("Id")
end
for _, button in pairs((script.Parent.Buttons:GetChildren())) do
local Dependancy = button:GetAttribute("Dependancy")
if Dependancy then
button.Parent = LockedButtons
script.Parent.PurchasedObjects.ChildAdded:Connect(function(child)
local id = child:GetAttribute("Id")
if Dependancy ~= id then end
button.Parent = script.Parent.Buttons
end)
end
button.ProximityPrompt.Triggered:Connect(function(player)
for _, purchases in pairs((TycoonFolder:GetChildren())) do
if player ~= script.Parent.Owner.Value then continue end
local IdOfItem = button:GetAttribute("IdOfItem")
local Id = purchases:GetAttribute("Id")
local Cost = button.Cost
if Id ~= IdOfItem then continue end
if Cost then
if player.leaderstats.Cash.Value < Cost.Value then
warn("you are broke")
return
end
player.leaderstats.Cash.Value -= Cost.Value
end
local purchaseClone = purchases:Clone()
purchaseClone.Parent = script.Parent.PurchasedObjects
button.Parent = UsedButtons
end
end)
end