I am trying to make this so that the script runs when the server is created and then when after some settings have been changed it disables some spawn bricks. My issue is when the player dies it seems the loop runs twice renabling my spawn locations. Is there any way to kill a player without using the function like I am using below?
game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(char)
while true do
local childs = game.Workspace.Map1:GetChildren()
for i,v in pairs(childs) do
if v.ClassName == "SpawnLocation" then
v.Enabled = true
end
end
char:BreakJoints()
wait(15)
local childs = game.Workspace.Map1:GetChildren()
for i,v in pairs(childs) do
if v.ClassName == "SpawnLocation" then
v.Enabled = false
end
end
local childs = game.Workspace.Map2:GetChildren()
for i,v in pairs(childs) do
if v.ClassName == "SpawnLocation" then
v.Enabled = true
end
end
char:BreakJoints()
end
end)
end)

2 comments
Well kinda what you said. I have several spawn locations located inside a model and so my intent is that this script over in this case 15 seconds will disable a set of spawn locations and renable another set as well as kill the player. As I noticed once the player dies my character function repeats and then theres 2 loops running at once.
There will be another loop spawned each time a Player dies. any player, because of how this is written. If you want per-player Spawns to work, you'll have to make a custom spawning function, and call it each time a Player dies.