GetChildren inside "Players.PlayerRemoving" is being TRIPLICATED

Works normal for me

local Players = game:GetService('Players')
Players.PlayerRemoving:Connect(function(player)
	local children = workspace.Dracolyx:GetChildren()
	for _,v in pairs(children) do
		print(v)
	end
end)

Could it be a failure for me to be using inside Studio?

Well if you don’t have any other scripts than just that, then the problem would be on Roblox’s side, since I tested in studio and it as well worked normally for me.

But if you have more scripts I suggest you analyze them to figure out if something may be creating duplicates of the parts when the player leaves, or maybe just duplicates in general something could be cloning multiples in one of your scripts. Other than that, the issue is a mystery to me.

Ask yourself these questions:

  • Have you disabled anything default that roblox offers?
  • Could it be a bug causing this to happen?
  • What did I do before this happened?

Why do you need duplicates? Is this just something you were experimenting?

It must be some bug in studio, like another user said the event could be running multiple times.

To combat this just create a guard clause.

local debounce = false

Players.PlayerRemoving:Connect(function(player)
    if debounce then return end
    debounce = true
    -- rest of code
end)

Thanks, but not this case, once I have a print at the beginning of the function and it prints only 1 time, but GetChildren is printing 3 times each part.
And as I said, it’ s happening only in ServerScript -> Players.PlayerRemoving:Connect(function(player), not in LocalScript.
It seems a Studio bug, but as I see, it’s happening only with me…

Wait, so did my suggestion work or not? I’m a bit confused. :confused:

No, once Players.PlayerRemoving is being fired only 1 time…

are you using the beta output?
if you are, could you try and see if the issue persists with the non-beta output?

Not the case, once the values are also triplicated inside a for loop…

	for i, item in ipairs(workspace.Esteiras:GetChildren()) do
		print(item.Name)
	end	

do you mind sharing the whole code?

What are you using this script for?

it’s hard to help someone when they are only sharing pieces of their code, for all i know they could have connections stacking upon each other, which causes his problem

Let’s leave it at that for now.
I appreciate everyone’s attention.
I’m sure that at some moment this mystery will be cleared up.
So I will put the solution here.
Thank you all.

And if it doesn’t get cleared up? Wouldn’t sharing the code you possess benefit yourself to figuring out the issue? We can work together to fix whatever is causing your character’s parts to triplicate.

This is killing me! :rage:

In addition to GetChildren listing 3 times each item (only if using GetChildren inside ServerScript, because in LocalScript it works ok), now I realized that even if I remove an object with Destroy(), the object correctly disappear from workspace but still will appear in GetChildren of ServerScript, that is, it is as if there is a different or outdated GetChildren within ServerScript.

The worst thing is that I tried to create a new project and do some simulations but I was not able to get the same problem, it only occurs in my current project.

Does anyone have any idea what is creating this nightmare?

Showing the whole code would help, because this would only result in printing the table’s memory address. Maybe it’s your code logic that’s causing it to print the children 3 times.

Does this happen with the non-beta console window too?

@Exeplex
I would have to submit my entire project, as this occurs when creating parts in the project; but the comments are in Portuguese, this will not make it much easier for you. The engine is also still complex and has some bugs in the interface, since the game is in development.
I just wanted to know if anyone has been there, but apparently not.

@NachtHemd this happens also with the non-beta console, the code was just to simplify, but a for/pairs also shows the part names incorrectly.

It’s most likely a bug in your framework then, try digging into the section of the output array creation, your answer could be there.

I’ll take the blame, because the reality is that I didn’t understand the Server->Client mechanism correctly.
I was doing everything wrong, thinking that parts that are created in LocalScript would be visible via Server and that caused all this confusion.
Over time and friends’ responses, (like my topic How to clone a part hosted in ServerStorage only for the current player? - #4 by rogeriodec_games), I realized that my approach would have to be different.
I’ll now redo my code using another structure and everything will be fine.
Thanks for your attention.