Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Trying to make all players in the game respawn after loop runs not working?

local Map = game.Workspace.Map
local number = 5



function reloadMap()

			
	game.Workspace.Map.Parent = game.ReplicatedStorage
	wait(1)
	game.Workspace:ClearAllChildren()
	wait(1)
	game.ReplicatedStorage.Map.Parent = game.Workspace

for _,v in pairs(game.Players:GetPlayers()) do -- how do i make it work like i want

v:LoadCharacter()

	end	
end


while wait(number)do
reloadMap()

end

-- If there is an easier way to clear workspace without deleting the player and unwanted folders please tell me.

1 comment

0

Your script ends up breaking at ClearAllChildren, Terrain can not be cleared from the Workspace, thus throwing an error stopping your script. Why clear the workspace after adding your map anyway?

1 answer

add another for _, v in pairs loop before respawning the players and put it instead of what you have clearing the workspace now:

for _, v in pairs(workspace:GetChildren()) do
	if not game.Players:FindFirstChild(v.Name) and not v.Name == "Terrain" then --[[ Checking if the models name is a player name
]]
		v:Destroy() -- Destroys it if it isn't.
	end
end

This should destroy everything in workspace besides parts with a players name or terrain. May have spelled terrain wrong btw..

2 comments

0

Im clearing the workspace for a reason, After a while in my script fighting game the workspace gets cluttered with parts and sounds, these would usually delete themselves after a few seconds but because of some weird lag or something they don't remove themselves and then cause lag for the entire server, thats why im clearing workspace then putting the map back into workspace.

0

yes, that will clear everything in the workspace besides the players and the terrain which would break if you tried to clear it

This discussion is preserved as it was. New answers, comments, and votes are closed.