part not getting properly GC'ed? help please?
Asked by
5 years ago Edited 5 years ago
i am trying to make a part spawn in the workspace when a player is added in a folder named "PartsInWorkspace".
my issue is, when the player leaves i dont think it deletes from the game and gets GC'ed.
my first issue is my game has ungodly amount of untracked data, about 500mb in a blank, new baseplate, and on a good day like 300mb, which makes my overall memory 700 and sometimes 450 to 600. i feel my only way is to work around it. otherwise i dont really know how i can do this game idea at all because when my player moves the data goes up and doesnt ever come back down, especially when i stop testing and reenter it, the memory jumps up about 10-50mb. when i test the game with Player1 etc, it drops to about 500mb maybe 450, but it rises over time and doesnt stop(this is in a blank baseplate with nothing, and usually happens when the player moves).
so i am testing the ability to work around it and i created this script (the original works fine, this is an example script of what im working with.) i am afraid it isnt getting GC'ed when the player leaves the game, because i still notice memory rising, it does drop but less than a single mb, and it rises faster than it drops. also, lua GC is usually at 0% which tells me nothing is really getting cleaned up.
i read about scope also, but it wasnt too clear. is this "out of scope"?
one more thing, i read about disconnecting events, but when i do it doesnt activate for other players so, i assume that cant be done with this. i read about "return" as well but i dont know what that does, or how to use it in this case very well.
Thanks, any help is appreciated the code is below:
04 | game.Players.PlayerAdded:Connect( function (player) |
06 | local parts = game.ServerStorage.parts:GetChildren() |
08 | local v = parts [ i ] :Clone() |
09 | if v.PartInfo.Value = = player:WaitForChild( "leaderstats" ).part.Value then |
11 | v.Parent = game.Workspace.PartsInWorkspace |
12 | for i,bc in pairs (v:GetChildren()) do |
13 | if (bc:IsA( "BasePart" )) then |
14 | bc.BrickColor = BrickColor.new( "Alder" ) |
23 | game.Players.PlayerRemoving:Connect( function (player) |
24 | for i,p in pairs (game.Workspace.PartsInWorkspace:GetChildren()) do |
25 | if (p:IsA( "BasePart" )) then |
26 | if p.Name = = player.Name then |