GetChildren inside "Players.PlayerRemoving" is being TRIPLICATED

During the game, I have 2 parts inside a folder like this:

If I print the parts inside my LocalScript, they are ok:

print(workspace.Esteiras:GetChildren())	

will show correctly:

But if I do the same inside here (ServerScript):

Players.PlayerRemoving:Connect(function(player)
	print(workspace.Esteiras:GetChildren())
end)

… it will show:

The 2 parts are being listed 3 times each by GetChildren. The objects are the same, same CFrame, same everything.

What’s wrong?

1 Like

I really don’t know I think that function runs as many times as the person presses the exit button or some other weird thing, but I’ve never seen that before.

1 Like

Maybe try adding a return to your code to end the function, not entirely sure. I have seen this myself though.

2 Likes

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?