“script.Parent.MouseButton1Click:Connect(function()
local folder = Instance.new(“Folder”)
folder.Parent = game.Workspace
while true do
local part = Instance.new(“Part”)
local partcounter = game.StarterGui.PartCounter
local partcountertext = partcounter.TextLabel
local part_count = #workspace.Folder:GetChildren()
partcounter.Enabled = true
partcountertext = part_count
wait(0.1)
part.Parent = folder
part.Anchored = false
part.Transparency = 0.5
end
end)”
then to stop
“script.Parent.MouseButton1Click:Connect(function()
local folder = game.Workspace:FindFirstChild(“Folder”)
folder:Destroy()
local partcounter = game.StarterGui.PartCounter
local partcountertext = partcounter.TextLabel
partcounter.Enabled = false
end)”
Ok, so I figured out that it is changing the parts number, but its not showing me the text it says visible & the PartCounter has enabled set to true so don’t know whats going on.
This is not a great approach for what you’re doing, every time you click on the button a new while loop is initiated and will never stop running. On top of that, you create a new folder every time it runs which explains why the code I provided doesn’t seem to work in your case. Let me tidy up your code a bit:
local part_storage = Instance.new("Folder")
part_storage.Name = "PartCounter"
part_storage.Parent = workspace
local is_running = false;
local function Reset()
for _, p in pairs(part_storage:GetChildren()) do
p:Destroy()
end
end
local function Create_Part()
local part = Instance.new("Part")
part.Transparency = .5
part.Parent = part_storage
end
local function Begin()
local timer = tick()
while is_running do
if tick() - timer >= .1 then
timer = tick()
Create_Part()
end
end
end
script.Parent.Activated:Connect(function()
is_running = not is_running
if is_running then
Begin() --//Begin part generation
else
--//When the player disables the generating parts
Reset()
end
end)
I’ve restructured your code a bit, see how this works out.