Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

(READ DESC) How would I script a gui that will update to the amount of Parts in my game?

So basically I scripted my game to infinitely generate parts or little blocks, and I wanted to add a counter to show how many blocks have been generated. How would I script that? I'm very new to scripting btw so please excuse my noobiness.

This is the script I used to make the parts spawn infinitely, if that helps.

while true do

wait(0.5)

part = Instance.new("Part")

part.Parent = game.Workspace

end

2 answers

Since you're starting out, it is probably best to learn how to make guis before you code them. Here's a basic tutorial on how to get started: https://youtu.be/egUMoynJz1g

For now, here's some simple code that will still be able to get the job done:

local message = Instance.new("Hint", workspace) -- this will add a little hint at the top bar
local counter = 0 -- this will count the parts in workspace
while true do
	wait(0.5)
	part = Instance.new("Part")
	part.Parent = game.Workspace
	counter = counter + 1
	message.Text = tostring(counter) -- tostring converts counter into a string, since it's originally a number
end

1 comment

0

No need to do game.Workspace, instead, just write workspace

First, make a folder in workspace

and change the script like this

while true do
	wait(0.5)
	Instance.new("Part", game.Workspace.YourFolder)
end

insert a localscript into text label in gui

local partFolder = game.Workspace.YourFolder

partFolder.ChildAdded:Connect(function()
	script.Parent.Text = #partFolder:GetChildren()
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.