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