-
What do you want to achieve? Keep it simple and clear!
Yeah topic name is complicated, so explonation there, for my game i will have a lot of SurfaceGUIs with a lot of properties, and i need to update some of them. I have 2 functions which working separately(one for updating upgradeFrame(where player buy smth)
this
Second for just updating all upgrade stuff on default screen
-
What is the issue? Include screenshots / videos if possible!
Issue is what updating and detecting these frames take too much time and creating some issues with that. - What solutions have you tried so far? Did you look for solutions on the Developer Hub? I tryed using coroutine functions there, but they still kinda don’t help
DefaultUpgrade Code:
function ClientFunctions:UpdateAllUpgrades(player)
for _,upgrade in pairs(player.PlayerGui.SurfaceGUIs:GetDescendants()) do
if upgrade:IsA("Frame") then
if CollectionService:HasTag(upgrade, "Upgrade")then
local UpgradeType = upgrade.Parent.Parent:GetAttribute("UpgradeType")
local UpgradeName = upgrade:GetAttribute("UpgradeName")
local CurrentLevel = ValueFixer(ClientData.GetUpgrade(player, UpgradeType, UpgradeName, "CurrLevel"))
local Cap = ValueFixer(ClientData.GetUpgrade(player, UpgradeType, UpgradeName, "Cap"))
local Price = ValueFixer(ClientData.GetUpgrade(player, UpgradeType, UpgradeName, "CurrPrice"))
local amount = ValueFixer(ClientData.GetValue(player, upgrade.Parent.Parent:GetAttribute("Currency"), "Current"))
upgrade.Price.Text = Price:GetSuffix(true)
if amount >= Price then
upgrade.Price.TextColor3 = Color3.new(0, 1, 0)
else
upgrade.Price.TextColor3 = Color3.new(0.666667, 0, 0)
end
upgrade.Level.Text = CurrentLevel:GetSuffix(true, 0).."/"..Cap:GetSuffix(true, 0)
elseif CollectionService:HasTag(upgrade, "Unlockable") then
local UpgradeName = upgrade:GetAttribute("UpgradeName")
local Check = ClientData.GetUnlockable(player, UpgradeName, "ifOwn", true)
local currLevel
if Check == true then
currLevel = 1
else
currLevel = 0
end
local Cap = ValueFixer(ClientData.GetUnlockable(player, UpgradeName, "Cap"))
local Price = ValueFixer(ClientData.GetUnlockable(player, UpgradeName, "CurrPrice"))
local amount = ValueFixer(ClientData.GetValue(player, upgrade.Parent.Parent:GetAttribute("Currency"), "Current"))
upgrade.Price.Text = Price:GetSuffix(true)
if amount >= Price then
upgrade.Price.TextColor3 = Color3.new(0, 1, 0)
else
upgrade.Price.TextColor3 = Color3.new(0.666667, 0, 0)
end
upgrade.Level.Text = currLevel.."/"..Cap:GetSuffix(true, 0)
end
end
end
end
here is a for loop, i think that’s one of problem
Also this is where both of functions get called
for _,upgrade in pairs(player.PlayerGui:WaitForChild("SurfaceGUIs"):GetDescendants()) do
if upgrade:IsA("Frame") and upgrade:GetAttribute("UpgradeName") then
local BackButton = upgrade.Parent.Parent.Parent.UpgradeFrame.BackButton
local BuyButton = upgrade.Parent.Parent.Parent.UpgradeFrame.BuyButton
if CollectionService:HasTag(upgrade, "Upgrade") then
upgrade.UpgradeFire.MouseButton1Click:Connect(function()
ClientFunctions:UpdateUpgradeFrame(player, upgrade, "Upgrade")
end)
elseif CollectionService:HasTag(upgrade, "Unlockable") then
upgrade.UpgradeFire.MouseButton1Click:Connect(function()
ClientFunctions:UpdateUpgradeFrame(player, upgrade, "Unlockable")
end)
end
end
end
So i need somehow to detect this some other way without for loops(because of delay) and i need some tips about that.