Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I set text based on how many children there are under the parent part?

Asked by 3 years ago

Hello! I'm a beginner scripter so don't expect me to know a lot. In my game,there's a part where when you hover over it once, it spawns 1 part. I'm trying to make a textlabel where when a part spawns, it says 1 and goes up by 1 whenever 1 part is spawned. I put the parent of the parts that are going to spawn to part3. The goal for the game is in a certain amount of time, the player has to hover over the block repeatedly until it reaches 150 parts. Here's the code for the textlabel:

01local text = game.StarterGui.ScreenGui.TextLabel.Text
02text = "0"
03 
04repeat
05    if game.Workspace.part3.ChildAdded then
06        local newtext = text + 1
07        text = newtext
08        wait(5)
09    end
10until text == "150"

I tried to do GetChildren() and a function but no luck. Any help would be appreciated!

2 answers

Log in to vote
0
Answered by
SuperPuiu 497 Moderation Voter
3 years ago
Edited 3 years ago

You can do:

01local textLab = game.StarterGui.ScreenGui.TextLabel
02local PartNumber = 1
03local Done = false
04local Time = 0
05 
06game.Workspace.part3.DescendantAdded:Connect(function(Descendant)
07if Descendant:IsA("BasePart") and PartNumber < 151 then
08PartNumber = PartNumber + 1
09textLab.Text = PartNumber
10elseif PartNumber == 150 then
11Done = true
12end
13       end
14end)
15 
16repeat wait(1)
17Time = Time + 1
18until Done
0
Doesn't seem to be working. I tried changing up the code as well but no luck. Do you want to see the code for creating the new parts? MarioLuigi3426 0 — 3y
0
yea iMazariuz 36 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

I would just put the code that change the text inside the code that adds a new part.

1function addPart()
2    --the code you use to add part--
3    thenewpart.Parent = part3
4    text = text + 1 -- this is the thing that change the thing

This in theory should work.

Answer this question