Script not updating map after no children?

Sup, I’m making a horror game with my friend. The player has to avoid a monster, collect batteries and find and unlock the exit with said batteries.

Players are put in a folder when they are in an ongoing match. The player is moved to a different folder when they exit the building. When all of the players have exited the building the folder is left with no children I used :GetChildren == 0 for this.

It detects if the folder has no children. Once it finds that out, it destroys the map and takes a clone of it from replicated storage to reset it.

The problem is that the map only resets while every player is in the lobby folder. After they start a new and exit the building the map doesn’t reset despite the folder having no children.

The script doesn’t react to changes of the amount of children in the folder.

If it has when a new server is started children it doesn’t reset the map.
If it doesn’t have children when a new server is started it resets the map
(I checked it using a part that is inside the ‘‘Playing’’ folder and destroyed it once a player leaves the building.)

The script:
(Server sided in ServerScriptService)

if #playing:GetChildren() == 0 then
			wait(.1)
			game.Workspace.Map:Destroy()
			game.Workspace.Interactables:Destroy()
			wait(10)
			--Map
			print()
			game.ReplicatedStorage.Map:Clone()
			game.ReplicatedStorage.Interactables:Clone()
			game.ReplicatedStorage.Map.Parent = workspace
			game.ReplicatedStorage.Interactables.Parent = workspace
			--Batteries
			game.ReplicatedStorage.Battery1.Parent = workspace
			game.ReplicatedStorage.Battery2.Parent = workspace
			game.ReplicatedStorage.Battery3.Parent = workspace
			game.ReplicatedStorage.Battery4.Parent = workspace
			game.ReplicatedStorage.Battery5.Parent = workspace
			game.ReplicatedStorage.Battery6.Parent = workspace
			--Battery UI
			game.StarterGui.BatteryHUD.Frame.B1.ImageColor3 = Color3.fromRGB(255, 0, 0)
			game.StarterGui.BatteryHUD.Frame.B2.ImageColor3 = Color3.fromRGB(255, 0, 0)
			game.StarterGui.BatteryHUD.Frame.B3.ImageColor3 = Color3.fromRGB(255, 0, 0)
			game.StarterGui.BatteryHUD.Frame.B4.ImageColor3 = Color3.fromRGB(255, 0, 0)
			game.StarterGui.BatteryHUD.Frame.B5.ImageColor3 = Color3.fromRGB(255, 0, 0)
			game.StarterGui.BatteryHUD.Frame.B6.ImageColor3 = Color3.fromRGB(255, 0, 0)
		end

Not asking anyone to rewrite anything just want to know why the script doesn’t react to changes.
Anything helps.

1 Like

send the full script, or is that all?

I don’t really think it’s needed but sure here it is:

local Players = game:GetService("Players")
local menu = game.Workspace.MainMenuFolder.Main.MainMenuUI.MainFrame.UILobby.Image
local Exit = game.Workspace.Map.HeavyContainment.Exit.OutsideExit
local Main = game.Workspace.MainMenuFolder.Main.MainMenuUI.MainFrame.UILobby

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAppearanceLoaded:Connect(function(char)
		char.Archivable = true
		char.Parent = workspace.PlayerFolder.Lobby.Choosing		
		local C1 = game.Workspace.PlayerFolder.Lobby.C1
		menu.MouseButton1Click:Connect(function()
			char.Parent = C1
			if #C1:GetChildren() == 1 then
				wait(6)
				char.Parent = C1.Parent.Parent.Playing
			end
		end)
		local playing = game.Workspace.PlayerFolder.Playing
		if #playing:GetChildren() > 0 then
			Main.MainLobby.Waiting.Text = "Ongoing game"
		end
		
		if #playing:GetChildren() == 0 then
			wait(.1)
			game.Workspace.Map:Destroy()
			game.Workspace.Interactables:Destroy()
			wait(10)
			--Map
			print()
			game.ReplicatedStorage.Map:Clone()
			game.ReplicatedStorage.Interactables:Clone()
			game.ReplicatedStorage.Map.Parent = workspace
			game.ReplicatedStorage.Interactables.Parent = workspace
			--Batteries
			game.ReplicatedStorage.Battery1.Parent = workspace
			game.ReplicatedStorage.Battery2.Parent = workspace
			game.ReplicatedStorage.Battery3.Parent = workspace
			game.ReplicatedStorage.Battery4.Parent = workspace
			game.ReplicatedStorage.Battery5.Parent = workspace
			game.ReplicatedStorage.Battery6.Parent = workspace
			--Battery UI
			game.StarterGui.BatteryHUD.Frame.B1.ImageColor3 = Color3.fromRGB(255, 0, 0)
			game.StarterGui.BatteryHUD.Frame.B2.ImageColor3 = Color3.fromRGB(255, 0, 0)
			game.StarterGui.BatteryHUD.Frame.B3.ImageColor3 = Color3.fromRGB(255, 0, 0)
			game.StarterGui.BatteryHUD.Frame.B4.ImageColor3 = Color3.fromRGB(255, 0, 0)
			game.StarterGui.BatteryHUD.Frame.B5.ImageColor3 = Color3.fromRGB(255, 0, 0)
			game.StarterGui.BatteryHUD.Frame.B6.ImageColor3 = Color3.fromRGB(255, 0, 0)
		end
	end)
end)
1 Like

Try print debugging. Add different, relevant print statements to parts of your code to locate where exactly things work and where things don’t.

1 Like

I already did that at the very start to see if it works. It works but it doesn’t react to updates.

1 Like

Explain by react to updates - what do you mean? What prints and what doesn’t print? Does everything print?

1 Like

It only prints if there are no children at the very start of a new server (I checked it using a folder and destroyed it later in game)

It doesn’t react to later changes.

1 Like

would you like to send the file so we can see? because its very confusing atm…

1 Like

lol

script doesn’t update the map even if the Playing folder is left with no children.

1 Like

add me to teamcreate rq lemme help

1 Like

the game isn’t owned by me so I can’t do that. I also can’t ask for the prem right now cuz the owner is probably asleep right now

oh well ill try to work on something and then ill send my stuff

ok this is what you need to do, go in the part which removes the player from the ‘playing’ folder and in there when the script removes the player, check how many persons are in the ‘playing’ folder

  1. The player gets moved but the map doesn’t reset.
1 Like