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:
01 | local text = game.StarterGui.ScreenGui.TextLabel.Text |
02 | text = "0" |
03 |
04 | repeat |
05 | if game.Workspace.part 3. ChildAdded then |
06 | local newtext = text + 1 |
07 | text = newtext |
08 | wait( 5 ) |
09 | end |
10 | until text = = "150" |
I tried to do GetChildren() and a function but no luck. Any help would be appreciated!
You can do:
01 | local textLab = game.StarterGui.ScreenGui.TextLabel |
02 | local PartNumber = 1 |
03 | local Done = false |
04 | local Time = 0 |
05 |
06 | game.Workspace.part 3. DescendantAdded:Connect( function (Descendant) |
07 | if Descendant:IsA( "BasePart" ) and PartNumber < 151 then |
08 | PartNumber = PartNumber + 1 |
09 | textLab.Text = PartNumber |
10 | elseif PartNumber = = 150 then |
11 | Done = true |
12 | end |
13 | end |
14 | end ) |
15 |
16 | repeat wait( 1 ) |
17 | Time = Time + 1 |
18 | until Done |
I would just put the code that change the text inside the code that adds a new part.
1 | function addPart() |
2 | --the code you use to add part-- |
3 | thenewpart.Parent = part 3 |
4 | text = text + 1 -- this is the thing that change the thing |
This in theory should work.