#ClearAllChildren() not working

267 messages · Page 1 of 1 (latest)

vale wagon
#
function destruction()
    local currentRooms = game.Workspace.CurrentRooms
    currentRooms:ClearAllChildren()
end```
No errors, just not working.
cosmic folio
#

did u call

#

the destruction

vale wagon
#

I tried

#

Also not working

ancient swan
#

try putting it in a while loop and adding a child to the currentRooms folder

vale wagon
#

It's a table so I can't use destruction()

ancient swan
#

and seeing if it just disappears

vale wagon
ancient swan
#

:ClearAllChildren() should work, that's the correct method

#

where are you calling it from?

vale wagon
#

I called it.

ancient swan
#

could you send a snippet of the code it's used at

cosmic folio
#

he cant

vale wagon
#
local rooms = game.ReplicatedStorage:WaitForChild("GeneratedRooms"):GetChildren()
local bases = game.Workspace.Bases:GetChildren()
local previousRoom

function generate()
    for i, base in ipairs(bases) do
        local chosenRoom = rooms[math.random(1, #rooms)]:Clone()
--        while true do 
--            if chosenRoom == previousRoom then
--                chosenRoom = rooms[math.random(1, #rooms)]
--            else 
--                break
--            end
--        end
--        chosenRoom:Clone()
--        previousRoom = chosenRoom
        chosenRoom.PrimaryPart = chosenRoom:WaitForChild("KillFloor")
        chosenRoom:SetPrimaryPartCFrame(base.CFrame)
        base:Destroy()
        chosenRoom.Parent = game.Workspace.CurrentRooms
    end
end

function destruction()
    local currentRooms = game.Workspace.CurrentRooms
    currentRooms:ClearAllChildren()
end

generate()

game.Workspace.WinPart.Touched:Connect(function(hit)
    if not hit.Parent:FindFirstChild("Humanoid") then return end
    destruction()
    task.wait(0.1)
    generate()
    game.Workspace.TeleportPart.CanTouch = true 
    task.wait(0.1)
    game.Workspace.TeleportPart.CanTouch = false
end)```
ancient swan
#

thank you

#

it might help to add a print statement in the destruction method to help see if it's running, and if it's actually doing anything when called

vale wagon
#

I'm trying

cosmic folio
#
function destruction()
    local currentRooms = game.Workspace.CurrentRooms
    currentRooms:ClearAllChildren()
end

destruction()
#

do this

vale wagon
#

It's calling

cosmic folio
#

also MAKE UR FUNCTIONS local, stop globalizainginging(idk this word)

vale wagon
#

But not not clearing anything

cosmic folio
#

its

#

server

#

side

#

or client side

vale wagon
#

Server

cosmic folio
#

ur

#

script

vale wagon
#

Server side

eager abyss
#

did you check is worked on server side?

vale wagon
#

Wdym

eager abyss
#

um try print("test")

cosmic folio
#
function destruction()
    print('yey first step')
    local currentRooms = workspace.CurrentRooms
    print("second step")
    currentRooms:ClearAllChildren()
    print("oh not my legs are broken")
end

destruction()
#

do this

vale wagon
#

The function is getting executed, but it's not clearing children

cosmic folio
#

tell me which print it stops

#

hope the legs are not broken

vale wagon
#

After pasting your script it worked

#

Idk why the hell

#

But it seems to work

ancient swan
#

only difference is how you located the CurrentRooms instance

#

weird

cosmic folio
#

ez

#

its just

#

being pro

#

(wtf I did)

vale wagon
#

It stopped working

#

Oh wtg

#

wth

cosmic folio
#

(fire)

vale wagon
#

lemme test something

#

5sec*

cosmic folio
#

wtf it highlight that shit for

eager abyss
#

is there any error message?

ancient swan
#
function destruction()
    local currentRooms = workspace.CurrentRooms
    print(`before: {#currentRooms:GetChildren()}`)
    currentRooms:ClearAllChildren()
    print(`after: {#currentRooms:GetChildren()}`)
end
#

this'll give you more information when running the destruction function

vale wagon
#

I think I had the exact same generation so it seemed to have worked but didn't.

cosmic folio
#

i

#

pro

vale wagon
#

Lemme test something else rq

#

Nah still not working

ancient swan
#

please post console output when done 🙏

vale wagon
#

Omg kill me

ancient swan
#

is it working again for no specific reason 😭

vale wagon
#

It was working, the problem was from somewhere else.

#

Imma try something else rq

eager abyss
cosmic folio
#

knew it but didnt want to say(wtf planet I am on)

ancient swan
#

you find a fix?

vale wagon
#

It seems to be generating multiple generation of rooms

#

ClearAllChildren is working

#

Maybe because I'm touching too much the winpart?

#

Idkkk

ancient swan
#

wait so

#

new problem?

vale wagon
#

Yes

#
local rooms = game.ReplicatedStorage:WaitForChild("GeneratedRooms"):GetChildren()
local bases = game.Workspace.Bases:GetChildren()
local previousRoom

function generate()
    for i, base in ipairs(bases) do
        local chosenRoom = rooms[math.random(1, #rooms)]:Clone()
--        while true do 
--            if chosenRoom == previousRoom then
--                chosenRoom = rooms[math.random(1, #rooms)]
--            else 
--                break
--            end
--        end
--        chosenRoom:Clone()
--        previousRoom = chosenRoom
        chosenRoom.PrimaryPart = chosenRoom:WaitForChild("KillFloor")
        chosenRoom:SetPrimaryPartCFrame(base.CFrame)
        base:Destroy()
        chosenRoom.Parent = game.Workspace.CurrentRooms
    end
end

function destruction()
    function destruction()
        local currentRooms = workspace.CurrentRooms
        print(`before: {#currentRooms:GetChildren()}`)
        currentRooms:ClearAllChildren()
        print(`after: {#currentRooms:GetChildren()}`)
    end
end

generate()

game.Workspace.WinPart.Touched:Connect(function(hit)
    if not hit.Parent:FindFirstChild("Humanoid") then return end
    task.wait(2)
    destruction()
    task.wait(0.1)
    generate()
end)```
#

Current script

#

Maybe I should put "for i = 10"?

#

Since there's 10 stages

#

I mean room

ancient swan
#

the way you have it set up

#

will just generate a random room for every single base that exists in the workspace upon function execution

#

i dont see anything wrong with that so long as that's what you want to happen

vale wagon
#

nvm I can't do this:

for i=10, base in ipairs(bases) do```
#

There's an error

#

base is an error actually

ancient swan
#

yeah that's not how pairs works

mighty mesaBOT
#

studio** You are now Level 16! **studio

vale wagon
#

the*

ancient swan
#
for i = 1,10 do
print(i)
end
#

regular for loop

vale wagon
#

Mhm

ancient swan
#
for k,v in pairs(bases)
print(v.Name) -- prints currently iterated base name
print(k) -- prints current key
end
#
for i,v in ipairs(bases)
print(v.Name) -- prints currently iterated base name
print(i) -- prints current index
end
#

idk why i took the time to write all that

#

sorry

#

remind me what the current behavior is and what you want the behavior to be?

ancient swan
vale wagon
#

Yes

#

But I got an idea of fix

ancient swan
#

every single time the WinPart is touched by an object with a humanoid sibling, it runs the destruction and generate code

#

if multiple of those fire within the 0.1s timeframe you dictated in the last few lines of the function bound to the touch event, they will all generate new rooms

vale wagon
#

My fix seems to work

#
local rooms = game.ReplicatedStorage:WaitForChild("GeneratedRooms"):GetChildren()
local bases = game.Workspace.Bases:GetChildren()
local previousRoom
local a = 0

function generate()
    for i, base in ipairs(bases) do
        if a >= 10 then a = 0 return end 
        local chosenRoom = rooms[math.random(1, #rooms)]:Clone()
--        while true do 
--            if chosenRoom == previousRoom then
--                chosenRoom = rooms[math.random(1, #rooms)]
--            else 
--                break
--            end
--        end
--        chosenRoom:Clone()
--        previousRoom = chosenRoom
        chosenRoom.PrimaryPart = chosenRoom:WaitForChild("KillFloor")
        chosenRoom:SetPrimaryPartCFrame(base.CFrame)
        base:Destroy()
        chosenRoom.Parent = game.Workspace.CurrentRooms
        a = a + 1
    end
end

function destruction()
    function destruction()
        local currentRooms = workspace.CurrentRooms
        print(`before: {#currentRooms:GetChildren()}`)
        currentRooms:ClearAllChildren()
        print(`after: {#currentRooms:GetChildren()}`)
    end
end

generate()

game.Workspace.WinPart.Touched:Connect(function(hit)
    if not hit.Parent:FindFirstChild("Humanoid") then return end
    task.wait(2)
    destruction()
    task.wait(0.1)
    generate()
end)```
#

Imma do some testing

#

It's sometimes working sometimes not

ancient swan
#

what so it just generates 10 rooms instead of one for every single base?

#

yeah it looks like a bit of a bandage on a bullethole solution

vale wagon
#

Maybe I could do something like if currentRooms > 10 then etc...

ancient swan
#

i take it you only want 10 rooms to be generated, yes?

vale wagon
#

I'm a dumbass

ancient swan
#
local generating = false
game.Workspace.WinPart.Touched:Connect(function(hit)
    if not (hit.Parent:FindFirstChild("Humanoid") or generating) then return end
    generating = true
    task.wait(2)
    destruction()
    task.wait(0.1)
    generate()
    generating = false
end)
vale wagon
#

The debounce was not placed well, at least, I think so.

ancient swan
#

fixes the bottom part so it only ever is generating a single set of rooms

#

if you want it to generate only 10, there's a simple solution to that too

#
function generate()
    for i, base in ipairs(bases) do
        if i > 10 then break end
        local chosenRoom = rooms[math.random(1, #rooms)]:Clone()
--        while true do 
--            if chosenRoom == previousRoom then
--                chosenRoom = rooms[math.random(1, #rooms)]
--            else 
--                break
--            end
--        end
--        chosenRoom:Clone()
--        previousRoom = chosenRoom
        chosenRoom.PrimaryPart = chosenRoom:WaitForChild("KillFloor")
        chosenRoom:SetPrimaryPartCFrame(base.CFrame)
        base:Destroy()
        chosenRoom.Parent = game.Workspace.CurrentRooms
    end
end
#

it will only iterate through the first 10 bases, but it works

#

if you want it to generate through 10 random bases, try this

ancient swan
#
function generate()
    local copy = bases
    while #copy > 10 do
      math.randomseed(tick())
      table.remove(copy,math.random(1,#copy))
    end
    for i, base in ipairs(copy) do
        if i > 10 then break end
        local chosenRoom = rooms[math.random(1, #rooms)]:Clone()
        chosenRoom.PrimaryPart = chosenRoom:WaitForChild("KillFloor")
        chosenRoom:SetPrimaryPartCFrame(base.CFrame)
        base:Destroy()
        chosenRoom.Parent = game.Workspace.CurrentRooms
    end
end
#

this one will iterate through 10 random bases instead of just the first 10

vale wagon
ancient swan
#

how many is it generating

vale wagon
#

Less

ancient swan
#

it might be 9

vale wagon
#

It is

ancient swan
#

just change i > 10 to i > 11

#

i > 10 should work

#

🤷‍♂️

vale wagon
#

It's still generating million of shit when I'm touching winpart

ancient swan
#

but that is why it is generating a million bases

vale wagon
#

Oh yeah debounce...

ancient swan
#

🎊

#

🥳

vale wagon
#

Still not working

ancient swan
#

wild

#

what's happening now

vale wagon
#

I'm slowly getting crazy

ancient swan
#

?

#

still making a million different bases?

vale wagon
#

Yes

ancient swan
#

did you replace the old function bound to the Touched event

#

or just add the script i wrote to the bottom

#

shit i might be dumb

#
local generating = false
game.Workspace.WinPart.Touched:Connect(function(hit)
    if generating or not hit.Parent:FindFirstChild("Humanoid") then print(`busy`) return end
    generating = true
    print(`generating = {generating}`)
    task.wait(2)
    destruction()
    task.wait(0.1)
    generate()
    generating = false
    print(`generating = {generating}`)
end)
vale wagon
#

No debounce in the function

ancient swan
#

comparators got me fucked up

vale wagon
#

xD

vale wagon
#

Imma try again

#

Still not working TvT

ancient swan
#

bruh

#

r u fr

vale wagon
#

But it's generating two, not hundreds.

#

20 rooms, not 10.

#

It somehow worked one time

#

Ahhhhhhhhhhhhhhhhh

ancient swan
#

added debug statements

vale wagon
#

I don't know what to do

ancient swan
#

it should only print generating = true once, 2.1 seconds before it prints generating = false

#

if it prints either of those multiple times something is up

vale wagon
#

Trying out

#

23:13:12.865 vinblancx committed a new version of script ServerScriptService.Generate - Studio
23:13:13.186 vinblancx's corridor @ 28 août 2023 23:13 auto-recovery file was created - Studio
23:13:14.852 event not detected - Server - PassStageScript:2
23:13:14.861 event not detected - Server - PassStageScript:2
23:13:31.981 ▶ busy (x2) - Server - Generate:37
23:13:32.314 generating = false - Server - Generate:38
23:13:32.314 ▶ busy (x25) - Server - Generate:37
23:13:34.436 event not detected - Server - PassStageScript:2
23:13:34.439 event not detected - Server - PassStageScript:2
23:13:34.445 generating = false - Server - Generate:45

ancient swan
#

oh my dumbass

#

😭

#

re

#

replace the script

vale wagon
#

???

ancient swan
#

again

#

im sorry

#

the print statements

#

i printed the variable before changing it

#

but those busy statements mean there is debounce

#

and it is working as intended

vale wagon
#

No problem, helping me is already really cool.

ancient swan
#

i just feel slow making stupid mistakes like that

vale wagon
#

23:16:12.092 busy - Server - Generate:37
23:16:12.192 generating = true - Server - Generate:39
23:16:12.192 ▶ busy (x12) - Server - Generate:37
23:16:14.329 event not detected - Server - PassStageScript:2
23:16:14.331 event not detected - Server - PassStageScript:2
23:16:14.340 generating = false - Server - Generate:45

ancient swan
#

and lord knows there are scripters out there reading these forums just lurking

#

yeah so it's working as intended

#

still generating 20 rooms instead of 10 though?

vale wagon
#

Yes

ancient swan
#

where is this script located

#

and there's only a single winpart, right?

vale wagon
#

ServerScriptService

ancient swan
#

one winpart and one instance of the script

vale wagon
#

There's two different touched event on the part.

ancient swan
#

elaborate

#

that's more than likely why

#

its buggin

vale wagon
#

One to teleport the player and the other one.

#

I can't teleport the player from ServerScriptService.

#

Or at least, I don't think so?

ancient swan
#

you absolutely can

vale wagon
#

Ohhh

ancient swan
#

try removing that other touched event

#

ignore the teleporting for now

#

ill teach you how to do that

#

just see if it makes 10 rooms instead of 20 now

vale wagon
#

Can I also change intvalues there?

ancient swan
#

like, generate more rooms?

vale wagon
#

Nah, for example:
exp.Value += 100

ancient swan
#

depends on what the context is

vale wagon
#

Here's the other script:

local debounce = true
script.Parent.Touched:Connect(function(hit)
    if not hit.Parent:FindFirstChild("Humanoid") then return end
    if debounce then
        debounce = false
        local pname = hit.Parent.Name

        local player = game.Players[pname]
        local lb = player:WaitForChild("leaderstats")
        local otherstats = player:WaitForChild("otherstats")

        local level = lb:WaitForChild("level")
        local wins = lb:WaitForChild("wins")
        local exp = otherstats:WaitForChild("exp")
        local stage = otherstats:WaitForChild("stage")
        
        game.Workspace.TeleportPart.CanTouch = true
        
        stage.Value = 0
        exp.Value = exp.Value + 500
        wins.Value = wins.Value + 1
        task.wait(2)
        game.Workspace.TeleportPart.CanTouch = false
        debounce = true
    end
end)```
ancient swan
#

there's a lot of weird situational things that you might want to happen server/clientside

#

just sorta have to experiment and look at how other people implement it

#

i dont see why that would cause it to execute the generate function twice

vale wagon
#

Same

ancient swan
#

especially considering the debug lines we implemented are being ran the correct amount

#

can you send the generate function here

#

i wanna add some debug code

vale wagon
#

full code

#
local rooms = game.ReplicatedStorage:WaitForChild("GeneratedRooms"):GetChildren()
local bases = game.Workspace.Bases:GetChildren()
local previousRoom

function generate()
    for i, base in ipairs(bases) do
        local chosenRoom = rooms[math.random(1, #rooms)]:Clone()
        --        while true do 
        --            if chosenRoom == previousRoom then
        --                chosenRoom = rooms[math.random(1, #rooms)]
        --            else 
        --                break
        --            end
        --        end
        --        chosenRoom:Clone()
        --        previousRoom = chosenRoom
        chosenRoom.PrimaryPart = chosenRoom:WaitForChild("KillFloor")
        chosenRoom:SetPrimaryPartCFrame(base.CFrame)
        base:Destroy()
        chosenRoom.Parent = game.Workspace.CurrentRooms
    end
end

function destruction()
    function destruction()
        local currentRooms = workspace.CurrentRooms
        print(`before: {#currentRooms:GetChildren()}`)
        currentRooms:ClearAllChildren()
        print(`after: {#currentRooms:GetChildren()}`)
    end
end

generate()

local generating = false
game.Workspace.WinPart.Touched:Connect(function(hit)
    if generating or not hit.Parent:FindFirstChild("Humanoid") then print(`busy`) return end
    generating = true
    print(`generating = {generating}`)
    task.wait(2)
    destruction()
    task.wait(0.1)
    generate()
    generating = false
    print(`generating = {generating}`)
end)```
ancient swan
#

the bases part confuses me personally

#

because you only ever get the children at the start

#

i guess they'd just be parented to nil but keep their cframe information

#

hmm

vale wagon
#

I've been coding for almost 5 hours straight, my brain is dying....

ancient swan
#

that's how it goes tbh

#

is there a reason the destruction function is nested like that

vale wagon
#

nested?

ancient swan
#
function destruction()
  function destruction()
    -- code goes here
  end
end
vale wagon
#

HUH

#

WOW

ancient swan
#

does it remove the old rooms properly

#

😭

#

because calling it like that is gonna do nothing

vale wagon
#

Maybe happened when pasted fixes.

#

Trying again

#

Omg...........

#

Lemme test one more time

#

I can't trust what I'm seeing

ancient swan
#

😭

#

i just know what's happening

vale wagon
#

Omg omg omg

#

It worked 3 times in a row

#

Can't be coincidence

#

TvT

ancient swan
#

it isnt

#

well

#

we got it working now

vale wagon
#

Yes TvT

#

I'm so dumb

ancient swan
#

🥳

#

no you're not

#

it's all a learning process

vale wagon
#

My brain is exploiding

ancient swan
#

mistakes are made in the process

#

there's still improvement ahead

vale wagon
#

Thanks for your help!

ancient swan
#

but i must work on my own shit

#

best of luck ark

#

🙏

vale wagon
#

Gl on your shit xD

#

Good night