#prolly an easy fix for those who are not a beginner at coding

196 messages · Page 1 of 1 (latest)

woeful light
#

yo so, what im trying to do, is js a beginner project because im getting back into coding so

ashen trellisBOT
#

studio** You are now Level 2! **studio

woeful light
#

ok so

#

i created a button which spawns parts into workspace, and than made it so when it spawns parts, you can press the button again to stop spawning parts.

#

prolly an easy fix for those who are not a beginner at coding

#

The problem im having rn is

#

making a button that clears the parts

#

idk if i just be using "findfirstchild" to find the parts or

#

smt else

#

i js need help on that

#

if anyone could help i would really appreciate it

fossil juniper
#

clears? use a for loop over all the buttons and do button:Destroy()

#

like

#
for i, button in Buttons do
button:Destroy()
end
#

if it's a folder of buttons you dont need to do find first child

woeful light
#

so it deletes all the parts

fossil juniper
#

yea

#

oh wait you mean button that clears parts

woeful light
#

yea

#

also sorry if this is dumb because im getting back into coding lol

fossil juniper
#

i see

#

did you create a folder of all the parts you want to destroy?

woeful light
#

spawn parts spawns them, and you can press clear to clear the parts

#

nah i didnt is it better if i do that

fossil juniper
#

yea

#

it makes it more organized

woeful light
#

alr wait

fossil juniper
#

and easier to access

#

alr

woeful light
#

im gonna show u the script i alr have rq

#

then add the parts to the folder

#
local button = script.Parent

button.MouseButton1Click:Connect(function()
    if parts then
        parts.Destroy()    
    else
        button.Text = "No parts found."
        wait(0.75)
        button.Text = "No parts found.."
        wait(0.75)
        button.Text = "No parts found..."
        wait(0.75)
        button.Text = "No parts found."
        wait(0.75)
        button.Text = "Clear parts."
    end
end)```
#

this is the clear parts button

#

and ill send the script for the create parts button

fossil juniper
#

alr

woeful light
#

wait btw

#

how do i send it in lua format

fossil juniper
#
lua
#

like that

#

where lua is the text

woeful light
#
local button = script.Parent
spawning = false
script.Parent.MouseButton1Click:Connect(function()
    if button.Text == "Spawn parts." then
        button.Text = "Stop."
        while button.Text == "Stop." do
            wait(0.01)
            local newpart = Instance.new("Part", game.Workspace)
            newpart.Position = Vector3.new(0,30,0)
            newpart.Anchored = false
            newpart.Name = "Spawnpart"
        end
    end
    if button.Text == "Stop." then
        button.Text = "Spawn parts."
    end
    
end)
fossil juniper
#

alr 1m

woeful light
#

npnp

fossil juniper
#

ill replicate this in studio

woeful light
#

alright

#

take your time

fossil juniper
#

oh wait you already did the spawn parts

woeful light
#

yea

fossil juniper
#

you can just spawn them in a folder

woeful light
#

yeah i just did that

fossil juniper
#

oh then just destroy all the parts in the folder:

local Parts = workspace.Parts
local button = script.Parent

button.MouseButton1Click:Connect(function()
    for _, part in Parts do 
        if part:IsA("BasePart") then
            part:Destroy()
        end
    end
end)
woeful light
#

ahh for loops

#

totally forgot bout that

fossil juniper
#

ye

woeful light
#

tysm broo

#

i appreciate it hella

#

was stuck on that for a while

fossil juniper
#

you might want to add a check if there is no folder

woeful light
#

since i have a check there already

#

is add the for loop in the if condition

#

i can do that right?

fossil juniper
#

ye

#
local Parts = workspace.Parts
local button = script.Parent

button.MouseButton1Click:Connect(function()
    for _, part in Parts do 
        if part:IsA("BasePart") then
            part:Destroy()
        elseif #parts == 0 then
            print("no parts. wil not destroy.")
        end
    end
end)```
woeful light
#

alright thanks bro

ashen trellisBOT
#

studio** You are now Level 3! **studio

fossil juniper
#

no problem

fossil juniper
# woeful light alright thanks bro
local Parts = workspace.Parts:GetChildren()
local button = script.Parent

button.MouseButton1Click:Connect(function()
    if #Parts > 0 then
        for _, part in Parts do 
            if part:IsA("BasePart") then
                part:Destroy()
            end
        end
    else
        print("no parts. will not destroy.")
    end
end)
#

also this is a more optimized way of doing it

#

if you want

woeful light
#

alr bet

#

also

#

to get the parts

#

could i do like

#
local parts = game.workspace.folder:GetChildren()
fossil juniper
#

yeah

woeful light
#

alright ty

#

and than i could do if parts >= 1 then ... right

#

last question ill ask @fossil juniper i feel bad bothering you

fossil juniper
woeful light
#

oh wait rq

#

i got an error

#

Players.Kousados.PlayerGui.ScreenGui.Clear parts..LocalScript:5: attempt to compare number < table - Client - LocalScript:5

#

new updated script btw

#
local parts = workspace.Parts:GetChildren()
local button = script.Parent

button.MouseButton1Click:Connect(function()
    if parts > 0 then
        for _, part in parts do
            if part:IsA("BasePart") then
                part:Destroy()
            end
        end
    else
        button.Text = "No parts found."
        wait(0.75)
        button.Text = "No parts found.."
        wait(0.75)
        button.Text = "No parts found..."
        wait(0.75)
        button.Text = "No parts found."
        wait(0.75)
        button.Text = "Clear parts."
    end
end)

#

im really sorry bout this btw

random tinsel
#

its supposed to be #parts

woeful light
#

ohh alr

fossil juniper
#

yeah it's #parts

#

you need the hashtag to indicate the amount

woeful light
#

alr ty no error message

#

but its still not working for some reason

fossil juniper
#

should work

#

paste the code

woeful light
#

alr

#

bruhh what its saying no parts detected

fossil juniper
#

show

woeful light
#

sorry i had smt

#

ill send it now

fossil juniper
#
local parts = workspace.Parts:GetChildren()
local button = script.Parent

button.MouseButton1Click:Connect(function()
    if #parts > 0 then
        for _, part in parts do
            if part:IsA("BasePart") then
                part:Destroy()
            end
        end
    else
        button.Text = "No parts found."
        wait(0.75)
        button.Text = "No parts found.."
        wait(0.75)
        button.Text = "No parts found..."
        wait(0.75)
        button.Text = "No parts found."
        wait(0.75)
        button.Text = "Clear parts."
    end
end)
woeful light
#

still aint working for sum reason

fossil juniper
#

weird

woeful light
fossil juniper
#

hm

woeful light
#

wait

#

nvm my idea didnt work

fossil juniper
#

since you're going to have parts anyway:

local parts = workspace.Parts:GetChildren()
local button = script.Parent

button.MouseButton1Click:Connect(function()
    if #parts > 0 then
        for _, part in parts do
                part:Destroy()
        end
    else
        button.Text = "No parts found."
        wait(0.75)
        button.Text = "No parts found.."
        wait(0.75)
        button.Text = "No parts found..."
        wait(0.75)
        button.Text = "No parts found."
        wait(0.75)
        button.Text = "Clear parts."
    end
end)```
#

i removed the other check

#

it should work

woeful light
#

alright]

ashen trellisBOT
#

studio** You are now Level 4! **studio

woeful light
#

dayum still didnt work

#

the folder is right and everything

#

if you think its right it might be sum wrong with the variables or something

fossil juniper
#

rlly?

try removing GetChildren

#

just do workspace.Parts

woeful light
#

okay

#

yeah idk i got this error

#

Players.Kousados.PlayerGui.ScreenGui.Clear parts..LocalScript:5: attempt to get length of a Instance value - Client - LocalScript:5

fossil juniper
#

ye

#

folder is an instance

#

so add getchildren

#

sorry btw

woeful light
#

npnp

#

bro i should be apoligizing

fossil juniper
#

nahh

#

btw look

#

i tested it and it didnt change the text

#

it just destroyed the parts

#

@woeful light might be a problem on your end

woeful light
#

yea

#

bro ivebeen getting this error every time i load the game

fossil juniper
#

what error

woeful light
#

this is probably really stupid by me because i didnt tell anyone

#

InsertService cannot be used to load assets from the client - Client

fossil juniper
#

oh

#

might be another script

#

also how are you adding the parts

#

paste that creating script again

woeful light
#

alr

#
local button = script.Parent
spawning = false
script.Parent.MouseButton1Click:Connect(function()
    if button.Text == "Spawn parts." then
        button.Text = "Stop."
        while button.Text == "Stop." do
            wait(0.01)
            local newpart = Instance.new("Part", game.Workspace.Parts)
            newpart.Position = Vector3.new(0,30,0)
            newpart.Anchored = false
            newpart.Name = "Spawnpart"
        end
    end
    if button.Text == "Stop." then
        button.Text = "Spawn parts."
    end
    
end)
fossil juniper
#

hmm

#
local button = script.Parent
spawning = false
script.Parent.MouseButton1Click:Connect(function()
    if button.Text == "Spawn parts." then
        button.Text = "Stop."
        while button.Text == "Stop." do
            task.wait(0.05)
            local newpart = Instance.new("Part")
            newpart.Position = Vector3.new(0,30,0)
            newpart.Anchored = false
            newpart.Name = "Spawnpart"
            newpart.Parent = workspace.Parts
        end
    end
    if button.Text == "Stop." then
        button.Text = "Spawn parts."
    end
    
end)```
woeful light
#

still not working bruhh

fossil juniper
#

does the spawning parts work?

woeful light
#

yeah it does

#

its just the deleting parts

fossil juniper
#

i dont even know then, it shouldnt say that there are no parts

woeful light
#

do u think it could be related to that error?

fossil juniper
#

i think

#

actually dont think so

#

insertservice relates to httpservice

#

wait for someone else to help

woeful light
#

yeah i just did

#

ohhh yeah ur right

fossil juniper
#

btw gtg man

#

maybe try a cloning method

#

from replicated service

#

hope i helped

woeful light
#

yeah u helped alot

#

tysm bro

woeful light
#

tysmm bro

#

okay so

#

im making a beginner project in which

#

you press a button, parts spawn, if you press it again, then they stop spawning

#

i coded that correctly

#

and it works

#

however now

#

im tryna create a clear parts button, thats the thing thats not working

woeful light
#

is the thing we created

#

and its not working and we have no idea why

#

alright

#

its just the local script

#

oh shitt my bad

#

alright

#

YOOO

#

IT WORKED

#

TYSM

#

cant believe i didnt think bout that bro

#

tysmmm @fervent fern @fossil juniper i really appreciate it

main wyvern
#

im no expert but I think you need to use a remote event for it to remove the parts on everyones end

ashen trellisBOT
#

studio** You are now Level 28! **studio

fossil juniper
#

cant believe i didnt think of that too

#

i gotta learn about moving variables into events lol