Any other way to count my placed parts in a folder reliably?

Im making a f3x building game where players can claim plots and build in them, using f3x. Im using a part counter script to limit the amount of parts a player can insert into their build to prevent lag, however I’ve noticed its not updating when actually in game compared to editing in studio. Let me elaborate…

image

In this image you can see I’ve manually inserted 4 parts into the “Build” folder using the explorer. When I run the game I get the amount printed out perfectly.

image

However, when iIm actually in game, using f3x, and I insert a part… The part goes into the build folder but the value stays at 4, when they’re may be 5 parts in the folder, the script continuously outputs 4. Even though the script is made to output the number of descendants of the build folder.

image

This is the simple script I’m using to print out the number.

I’m guessing this is something to do with roblox itself and not the code? Is there any way I’d be able to fix this and have the value get correctly printed out?

(Note: Ignore the PartCount value, I realized it has no used and I’ll remove it later but for now the SetPartCount script is sitting in it.)

Instance:GetDescendants() and Instance:GetChildren() will get the descendants / children at the time that you called them. The table will not update from then on. To fix this, keep on calling Instance:GetDescendants() inside of the loop to re-get the descendants inside of the Instance.

3 Likes

You reference partsnumber outside of the while loop, meaning that it remains the same value.
This fix this simply wrap the partsnumber variable inside the while loop, that way it checks how many parts are in the folder every 0.5 seconds

-what qut100 said

2 Likes

Is the Part being created in a LocalScript?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.