#prolly an easy fix for those who are not a beginner at coding
196 messages · Page 1 of 1 (latest)
** You are now Level 2! **
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
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
so it deletes all the parts
spawn parts spawns them, and you can press clear to clear the parts
nah i didnt is it better if i do that
alr wait
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
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)
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)
alr 1m
npnp
ill replicate this in studio
oh wait you already did the spawn parts
yea
you can just spawn them in a folder
yeah i just did that
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)
ye
you might want to add a check if there is no folder
i think what ill do
since i have a check there already
is add the for loop in the if condition
i can do that right?
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)```
alright thanks bro
** You are now Level 3! **
no problem
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
alr bet
also
to get the parts
could i do like
local parts = game.workspace.folder:GetChildren()
yeah
alright ty
and than i could do if parts >= 1 then ... right
last question ill ask @fossil juniper i feel bad bothering you
dont think that's needed, > 0 is just checking if there are more than 0 parts
no worries !
alright
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
its supposed to be #parts
ohh alr
show
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)
still aint working for sum reason
weird
same as this
hm
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
alright]
** You are now Level 4! **
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
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
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
what error
this is probably really stupid by me because i didnt tell anyone
InsertService cannot be used to load assets from the client - Client
oh
might be another script
also how are you adding the parts
paste that creating script again
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)
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)```
still not working bruhh
does the spawning parts work?
i dont even know then, it shouldnt say that there are no parts
do u think it could be related to that error?
i think
actually dont think so
insertservice relates to httpservice
wait for someone else to help
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
so now this
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
im no expert but I think you need to use a remote event for it to remove the parts on everyones end
no problem lol
** You are now Level 28! **