I’m using the follow code to make a 10x summon system:
Summon_Event10x.OnServerInvoke = function(Player)
local UnitsInventory = Player:WaitForChild("UnitsInventory")
local Gems = Player:WaitForChild("Gems")
if Gems.Value < 400 then return end
Gems.Value = Gems.Value - 400
local Units = {}
local Banner = CurrentBanner
for i = 1,10,1 do
local Chance = math.random(1,100)
local Counter = 0
for _,Unit in pairs(Banner) do
Counter = Counter + tonumber(Unit.Percentage)
if Chance <= Counter then
local UnitInstance = Instance.new("StringValue")
UnitInstance:SetAttribute("UUID",HttpService:GenerateGUID())
UnitInstance.Name = Unit
UnitInstance.Value = Unit
UnitInstance.Parent = UnitsInventory
table.insert(Units,Unit.Name)
break
end
end
end
return Units
end
However when this RemoteFunction is Invoked there is a lot of lagged/frame rate drops to 0. Is there anyway to make this better/reduce or if possible prevent lag/FPS drop?
This is the new code, and it’s better but the FPS still drops a lot and there is a lot of lag still
Summon_Event10x.OnServerInvoke = function(Player)
local UnitsInventory = Player:WaitForChild("UnitsInventory")
local Gems = Player:WaitForChild("Gems")
if Gems.Value < 400 then return end
Gems.Value = Gems.Value - 400
local Units = {}
local Banner = CurrentBanner
local UnitTemplate =
for i = 1,10,1 do
local Chance = math.random(1,100)
local Counter = 0
for _,Unit in pairs(Banner) do
Counter = Counter + tonumber(Unit.Percentage)
if Chance <= Counter then
local UnitInstance = UnitTemplate:Clone()
UnitInstance:SetAttribute("UUID",HttpService:GenerateGUID())
UnitInstance.Name = Unit.Name
UnitInstance.Value = Unit.Name
UnitInstance.Parent = UnitsInventory
table.insert(Units,Unit.Name)
task.wait()
break
end
end
task.wait()
end
return Units
end
Alright, I figured out the problem. Basically it had little to do with the server script but all to do with the way I was handling the Units being added to the inventory. [I fixed it]