So, I’m currently making a coin pickup system for my halloween game, however there seems to be a problem.
After I’ve collected around 20 or so coins, my fps drops every time I pick up a “coin” and whenever a new one is made. I’ve tried everything I could think of to reduce anything that might cause low fps, but so far, nothing. Any help would be appreciated!
You´re script is intensly hard to execute. I have seen various coroutine.wrap functions and the complexities with the tables nearly makes this look like it was designed to drop FPS. Instead of using a table to store data, try creating a folder in the script and using Instance.new() and make a boolean or IntValue or whatever you need and try using that. You need to understand how complex and how much the game has to work to do this much.
The goal is not to eliminate coroutine. The goal is to make the scripts use it at least as possible and efficiently. And yes, heartbeats can help with the lag. If you do need to replace coroutine, you can use spawn() but I wouldnt highly recommend it.
Why would using actual instances rather than tables be more efficient? Doesn’t it require more memory to create instances rather than using tables which can be required in one swift manner?
You have a point, however you have to realize he is inserting data into another table. At this point, it gets really hard to understand the lag each solution causes.
local candyAddQue = coroutine.wrap(function()
while true do
wait(.1)
for index, queData in pairs(que) do
local plr = queData.plr
local amt = queData.amt
DS2Handler("Increment","candycoins",plr,amt)
candyEvent:FireClient(plr,"addCoins",amt)
table.remove(que,index)
end
end
end)()
I am not completely sure what this is for, however, if you are trying to remove a value at the same time, this will add to script lag. Assuming if you are just checking for something, just use a and statement before adding the values to the table. This should help with lag at great values.