#ClearAllChildren() not working
267 messages · Page 1 of 1 (latest)
try putting it in a while loop and adding a child to the currentRooms folder
It's a table so I can't use destruction()
and seeing if it just disappears
It has childs.
Yes
:ClearAllChildren() should work, that's the correct method
where are you calling it from?
I called it.
could you send a snippet of the code it's used at
he cant
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)```
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
I'm trying
function destruction()
local currentRooms = game.Workspace.CurrentRooms
currentRooms:ClearAllChildren()
end
destruction()
do this
It's calling
also MAKE UR FUNCTIONS local, stop globalizainginging(idk this word)
But not not clearing anything
Server
Server side
did you check is worked on server side?
Wdym
um try print("test")
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
The function is getting executed, but it's not clearing children
(fire)
wtf it highlight that shit for
is there any error message?
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
I think I had the exact same generation so it seemed to have worked but didn't.
Imma try this
please post console output when done 🙏
Omg kill me
is it working again for no specific reason 😭
then delete prints and try it again
knew it but didnt want to say(wtf planet I am on)
you find a fix?
It seems to be generating multiple generation of rooms
ClearAllChildren is working
Maybe because I'm touching too much the winpart?
Idkkk
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
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
nvm I can't do this:
for i=10, base in ipairs(bases) do```
There's an error
base is an error actually
yeah that's not how pairs works
** You are now Level 16! **
the*
Mhm
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?
it's generating too many rooms right now?
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
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
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
Maybe I could do something like if currentRooms > 10 then etc...
does this sound accurate
i take it you only want 10 rooms to be generated, yes?
I'm a dumbass
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)
The debounce was not placed well, at least, I think so.
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
Trying it
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
It's not generating 10 rooms somehow
how many is it generating
Less
it might be 9
It is
It's still generating million of shit when I'm touching winpart
did you add this
idk if you saw this the first time i posted it or the first time i replied to it
but that is why it is generating a million bases
Oh yeah debounce...
this is your brand new debounce script
🎊
🥳
Still not working
I'm slowly getting crazy
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)
No debounce in the function
comparators got me fucked up
xD
fixed
But it's generating two, not hundreds.
20 rooms, not 10.
It somehow worked one time
Ahhhhhhhhhhhhhhhhh
added debug statements
I don't know what to do
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
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
???
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
No problem, helping me is already really cool.
i just feel slow making stupid mistakes like that
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
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?
ServerScriptService
one winpart and one instance of the script
There's two different touched event on the part.
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?
you absolutely can
Ohhh
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
Can I also change intvalues there?
like, generate more rooms?
Nah, for example:
exp.Value += 100
depends on what the context is
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)```
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
Same
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
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)```
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
I've been coding for almost 5 hours straight, my brain is dying....
that's how it goes tbh
is there a reason the destruction function is nested like that
nested?
Wdym?
function destruction()
function destruction()
-- code goes here
end
end
does it remove the old rooms properly
😭
because calling it like that is gonna do nothing
Maybe happened when pasted fixes.
Trying again
Omg...........
Lemme test one more time
I can't trust what I'm seeing
My brain is exploiding
Thanks for your help!