I’m working on a tycoon framework. More specifically, the function that allows buttons that depend on prior purchases to appear only once those purchases have been made. Essentially, I just need to wait until new child is added to the purchases folder and make the button appear. However, I thought of two ways of doing this and wondered which is better practice.
The first is using WaitForChild(), listening for each dependency.
for i,button in pairs(Tycoon:WaitForChild("Buttons"):GetChildren()) do
spawn(function()
if button:FindFirstChild("Config") then
coroutine.resume(coroutine.create(function()
for i,dep in pairs(Config.Dependency:GetChildren()) do
Tycoon.Purchased:WaitForChild(dep.Value)
end
--spawn in button
end))
end
end)
end
The second is using .ChildAdded, and checking if the purchase is the same as the dependency.
for i,button in pairs(Tycoon:WaitForChild("Buttons"):GetChildren()) do
spawn(function()
if button:FindFirstChild("Config") then
for i,dep in pairs(Config.Dependency:GetChildren()) do
Tycoon.Purchased.ChildAdded:Connect(function(purchase)
if purchase.Name == dep.Value then
--spawn in button
end
end)
end
end
end)
end
I couldn’t find any topics comparing the two options and I wanted to know which, if either, is better practice. Or is there a better way than either of these that I’m not thinking of? Thanks.