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:

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!

2 answers

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

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
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.

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.

Answer this question