Why wont my part counter work?

I’m making a building game where players get their own plots assigned to them. I wanted each player’s plot to have its own PartLimit (To prevent lag), I initially thought I could do this by just using a value to update to the plot’s part count but it doesn’t seem to be working for some reason.

This is my explorer,
image

and this is the script.
image

Basically the script gets the descendants of the build folder (Where all the parts go) and counts them up, setting the counter to the “PartCount” value. I’m using descendants in case a player groups parts together.

Whenever I press play I just get an error message and nothing happens,
image

I’m relatively new to scripting so I don’t seem to understand this issue yet. If anyone could help me out it would be extremely appreciated. I’m just looking for a way to fix this or even possibly use another way.

Just a heads up, in that screenshot I changed the script to GetChildren() to see if that was part of the issue, it wasnt. The original script uses GetDescendents().

In a while loop, you must use wait() to prevent the loop from running too fast, thus creating that error.
You should use partCount = script.Parent then add .Value to the end of each reference to it because accessing its value gives a copy of it’s value, not itself
Also I recommend changing partCount = partCount + 1 to partCount += 1 to make it easier to read

1 Like

I’ve changed the script with your advice,

image

however when I’m actually in game and I insert parts into the build folder, the PartCount value still stays at 0.

I think it might have something to do with the way im inserting the parts or something like that…??

value must be capitalized (Value)

1 Like

You can also just use #parts:GetDescendants() to retrieve the number of parts (descendants()

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