local PlayerAnimationsCache = {}
local PlayerCurrentAnimators = {}
local PlayerDebounces = {} -- Store debounces for m1 for each player
for all weapon script (server script) i have. each weapon will have a script
and at the end of script, i have this to prevent memory leak
function onPlayerRemoving(player)
PlayerAnimationsCache[player.UserId] = nil
PlayerCurrentAnimators[player.UserId] = nil
PlayerDebounces[player.UserId] = nil
end
game.Players.PlayerRemoving:Connect(onPlayerRemoving)
would this cause a problem as more weapons are added to a game? The thing im worrying about is this would run for a player who does not even own that weapon and 25 scripts (weapons ) will run when player leaving as well.
Feel free to tell me a better way to do this as well. I’d appreciate a lot!
this is ChatGPT said so far “” Having the PlayerRemoving connection for each weapon in your game, even if you have around 100 weapons, should not cause significant lag. The PlayerRemoving event is a standard way to clean up player-specific data when a player leaves the game, and it’s a common practice in Roblox game development." But i have no way to verify this~~
So you have this script, in 100 different weapons? Wouldn’t it just be better to use a loop. Regardless, even if you didn’t, I don’t think 100 different events removing these items from the table wont cause any major issues, but it is certainly not the most efficient way