Asked this quest last time and people found it hard to read. So, I removed all the code that won't be necessary (I hope)... Making a tycoon from scratch but I feel that the script may start to lag in the future. So wanting to know if there is any way to improve these lines of code to improve performance in the future. So I have shortened the script to the minimum and tried my best to explain things I omitted. No errors
-- 3 For loops ( Nested ) to get {Floor, SubCategory = {BasicItems, UpgradeItems, RebirthItems}, Tiers}
-- From for loop, used Floor and Tier to obtain module script which holds the button stats {Folder > Floor > Tier}
-- PurchasedModel is where items goes after being bought {PurchasedModel > Floor > SubCategory > Tier}
-- Rebirth is the player's rebirth value
-- ButtonSubCategory is in button stats (Module script)
local TotalDependents = {}
local HasMultiple = string.match(ButtonStats["Dependent"], "%; ") -- If button has more than 1 item to wait for
coroutine.resume(coroutine.create(function()
if HasMultiple then
for _, v in pairs(string.split(ButtonStats["Dependent"], "; ")) do
TotalDependents[v] = false
end
end
PurchasedModel[Floor.Name][SubCategory.Name][Tiers.Name].ChildAdded:Connect(function(Child)
if TotalDependents[Child.Name] ~= nil then
TotalDependents[Child.Name] = true
end
end)
for DependentName, Value in pairs(TotalDependents) do
if TotalDependents[DependentName] == false then
repeat -- Repeats until all dependents are true
wait(.125)
until TotalDependents[DependentName] == true
end
end
if ButtonSubCategory == "Rebirth" then
if Rebirth < ButtonStats["Rebirth"] then
repeat -- Repeat until player's rebirth is of required amount
wait(.125)
until Rebirth >= ButtonStats["Rebirth"]
end
end
end))
From the above code:
for DependentName, Value in pairs(TotalDependents) do
if TotalDependents[DependentName] == false then
repeat -- Repeats until all dependents are true
wait(.125)
until TotalDependents[DependentName] == true
end
end
This repeat wait until... might lag the game is the future. Wanted to know if it is possible to used another method instead of a repeat until loop. Also other method for spawn(function()? (iirc, it slows the start of the game)
