Spawns arent disabling

so i have this thing in my script where it disables spawns in a lobby but its not disabling them

ServerStorage = game:GetService("ServerStorage")
ReplicatedStorage = game:GetService("ReplicatedStorage")
Players = game:GetService("Players")
teams = game:GetService("Teams")

Maps = ServerStorage:WaitForChild('Maps'):GetChildren()
RoundStatus = ReplicatedStorage:WaitForChild('RoundStatus')

lobbyspawns = game.Workspace.Lobby.Spawns:GetChildren("SpawnLocation")

local Survivors = {}

while wait() do
	if #game.Players:GetPlayers() >= 2 then

		local countdown = 10
		for i = countdown, 0, -1 do
			RoundStatus.Value = "Intermission: "..i
			wait(1)
		end

		ChosenMap = Maps[math.random(1, #Maps)]:Clone()
		Spawns = ChosenMap:GetChildren("SpawnLocation")
		
		lobbyspawns.Enabled = false

		RoundStatus.Value = ChosenMap.Name.." has been chosen!"

		wait(5)

		countdown = 1
		for i = countdown, 0, -1 do
			ChosenMap.Parent = workspace
			RoundStatus.Value = "Teleporting everyone..."

			local Players = game.Players:GetPlayers()

			for _, Player in ipairs(game.Players:GetPlayers())do
				if Player.Character and Player.Character:WaitForChild('Humanoid') then
					RandomSpawn = Spawns[math.random(1, #Spawns)]
					Player.Character.HumanoidRootPart.CFrame = RandomSpawn.CFrame
					Player.Character.Humanoid.MaxHealth = 100
					Player.Character.Humanoid.Health = 100
					Player.Character.Humanoid.WalkSpeed = 16
					Survivors[Player] = true
				end
			end

			wait(1)
		end

		countdown = 300
		for i = countdown, 0, -1 do
			RoundStatus.Value = "Game in progress: "..i

			wait(1)
		end
		
		RoundStatus.Value = "Round Over!"
		wait(5)
		lobbyspawns.Enabled = true

	else
		local dots = "..."

		repeat
			for i = 1,3 do
				RoundStatus.Value = "Waiting For Players"..string.sub(dots, 1, i)
				wait(1)
			end
		until #game.Players:GetPlayers() >= 2
	end

end

Not sure if you are trying to stop spawning just at a certain spawn point or all together but try disabling the autoload
game.Players.CharacterAutoLoads = false

You ever check your console when your code doesn’t work? You should try debugging your code first before posting a thread here; remember, this category isn’t for people to spoonfeed you code or fixes, it’s to help you learn and understand what you did wrong so you can expand your knowledge.

The two problems involve your misuse of GetChildren. If you read up on the function’s usage on the Developer Hub, you may be able to understand a bit why this happened. GetChildren does not accept any arguments, it only returns a list of immediate children to the object you ran it on. You need to go over this list, see if the current item being checked is a SpawnLocation and then set the Enabled property accordingly.

There are code samples on the GetChildren page you can reference to see how to use the function. As for debugging, you can access the Developer Console with F9 or find it under the View tab of the ribbon bar in Studio. Please debug your code before posting threads.

2 Likes

i only want some of the spawns disabled, defined in the variable

but getchildren() worked for another part of the code

That’s because you used it correctly in that case. You did not use it correctly in the case of the SpawnLocations. Please read carefully over the advice I’ve provided you and work to fixing your code. Put a bit of time and effort into reviewing your code.

I’m pretty sure what @lesserfantasy is trying to say is that the function Spawns:GetChildren() only returns a table with the folder/model’s children directly under that instance. So what you want to do instead is use a for I, V in pairs() loop and disable V each time. Here’s what I mean:

local RunService = game:GetService("RunService")
for I, V in pairs(lobbyspawns) do
        V.Enabled = false
        RunService.Heartbeat:Wait()
end

You want to use RunService.Heartbeat:Wait() instead of wait() as it’s faster and all there’s an article on it if you want a link to it but for right now I’ll just say it’s better.

1 Like

I’m not too sure why you’re rephrasing my words when it’s clear what I intended to say. On another note, for the for loop, you don’t need any kind of wait at all on it. When iterating over a small number of instances for something as trivial as flipping a boolean property, waits are unnecessary.

I was just elaborating because he seems to be confused on what you meant. Also I didn’t know you don’t need a wait on for loops, in my experience I’ve had a loop tell me the thread timed out because the script handler couldn’t change the properties as fast as it was and found out it was because of replication. It might have been an old engine error but we don’t know how many spawn points he wants to disable so I had it wait for every physical simulation frame just to be sure it doesn’t try and process too much at once.

and i used it the same way[quote=“lesserfantasy, post:3, topic:894376”]
You ever check your console when your code doesn’t work?
[/quote]

by the way i didnt give any error from console because it never gave me anything

If your answer solves his problem then he can mark the answer as your reply I don’t care about reputation or whatever I was just trying to help.

1 Like

thank you!! i just tried out what you told me to do and it worked!