Iam making a game like eat blobs simulator
And every time i mada a spwan system it did lag
So if there is someone who plays this type of game and knows this type of spawning system and how it works, please help me.
This is my system
the script:
local SlimeChooser = require(script.SlimeChooser)
local RunService = game:GetService('RunService')
-- i will stop the heartbeat but i made it open to see the minimum number of slimes that will be good for the game and less laggy
RunService.Heartbeat:Connect(function() -- i used wait(0.1) and it also lagged
local Slime = SlimeChooser.ChooseSlime()
local SlimeClone = Slime:Clone()
SlimeClone.Parent = workspace.slimes
SlimeClone.Position = Vector3.new(math.random(-256, 256), 1, math.random(-256, 256))
end)
the module script:
local module = {}
local ServerStorage = game:GetService('ServerStorage')
local slimsFolder = ServerStorage:WaitForChild('slimes')
local slimes = {
['legendry'] = slimsFolder.legendry,
['epic'] = slimsFolder.epic,
['rare'] = slimsFolder.rare,
['common'] = slimsFolder.common,
}
local rarity = {
['legendry'] = 2,
['epic'] = 8,
['rare'] = 20,
['common'] = 70
}
function module.ChooseSlime()
local RandomNum = math.random(1,100)
local counter = 0
for rarity, weight in rarity do
counter += weight
if RandomNum <= counter then
local slime = slimes[rarity]
return slime
end
end
end
return module