-
I’m working on a Bumper Cars game, and I am trying to have multiple cars running via coroutines without too much lag.
-
After a player’s character is removed, the current running coroutine for that car is yielded, the car is deleted, and if the player respawns, another car and its required coroutines are recreated. But every time the player respawns, it becomes a little more laggy.
-
Assuming yielded coroutines do cause lag, I need help finding a way to completely remove the coroutine from the game. If they do not, I will need other ideas of how respawns might cause lag?
Here’s the code I’m most suspicious of (It does seem a bit inefficient anyway, so are there any suggestions of how I can alternatively run this function? While letting the script continue handling the game)
-- ModuleScript
Car.RunEngine = function(player)
local run = coroutine.wrap(function()
while wait() do
player.CharacterRemoving:connect(function()
coroutine.yield()
end)
-- code for running the car engine
end
end)
run()
end