Hello everyone! I’ve recently made a game and I’m ready to release it, but there’s one problem I’ve been encountering. In the game, you can gain loads of new pets and items. But, if you gain too many then it will start to lag and become unplayable. Here is a video to show what is going on:
Are you running those coins, pets etc. in the server side? If you do it on the server side it clogs network bandwith. Try rendering it on Client side, maybe it could help
Each pet has its own script and checks if “AutoClicker” is on. If autoclicker is on then it will start spawning in blocks every couple of seconds at the pets position. This action is controlled in a while loop. Is having multiple scripts the cause?
Here is a snippet of the code used in each pet script:
task.spawn(function()
while wait(2) do
local Data = require(Owner:WaitForChild("PlayerData"))
if MarketplaceService:UserOwnsGamePassAsync(Owner.UserId, AutoclickerId) and Data.AutoClickerToggled then
-- block spawning code
end
end
end)
Also I’d suggest making a centralized system for processing AI of the pets. I’d suggest looking into Tags for efficient direct access to specific group of tagged AIs.
The reason I have it set up like that is because the data changes, and if I get it once, it will stay the same and won’t update. (Correct me if I’m wrong)
Well usually in most games if the player buys a gamepass they need to rejoin. But you could do so it runs the checks after the player purchased the gamepass and apply the corresponding attributes.
No, it’s not worse. It applies an attribute on the player once, depending if it initially found a gamepass in possession or when a player purchased one.
The way you’ve done it constantly checks if a player has a gamepass every 2 seconds, which isn’t needed at all. You just have to save the result once, as I’ve suggested using an attribute.
bruh all coin effects like this should always be client sided.
also you want to probably use task.defer instead of task.spawn. And why are you requiring the data every 2 seconds? I agree with @VioletElementalist – you need to control all the pets in a single script. You should probably take a look into collection service.