How could i force respawn all players?

hello! i’m trying to work on a map loading script and now i want to integrate a force respawn into it. i’ve tried something like:

players = game:GetService("Players")
player = players.LocalPlayer

player:LoadCharacter()

but it didn’t work
here’s the full script:

local mapfolder = game.Lighting.Maps
local maps = mapfolder:GetChildren()
local roundtime = script.RoundTime
local musicFolder = game.Lighting.Music
while true do
print ("loop starting")
	local chosenmap = maps[math.random(1,#maps)]
	local currentmap = chosenmap:Clone()

	currentmap.Parent = game.Workspace
	currentmap:MakeJoints()
	local music = musicFolder[chosenmap.Name]:Clone()
	music.Parent = workspace
	music:Play()
print (chosenmap.Name)
print ("was chosen!")
print (music.Name)
print ("music is now playing!")
print("now initating a 5 minute wait till next round")
wait(10)
	print("map destroyed, restarting loop")
	
	currentmap:Destroy()
	music:Destroy()
end

thanks for reading!

3 Likes

Make sure this is a server script,

for index,player in pairs(game:GetService("Players"):GetPlayers()) do -- gets all the players
      player:LoadCharacter() -- forces the respawn
end
12 Likes

will it work if I just do this instead of looping the player through a table?

local player = game:GetService("Players"):GetPlayers()

player:LoadCharacter()

That just returns a table of players, so it doesn’t work since it is a table, it must be an instance with the class name as Player.

Oh, alrigh… Thanks! :slight_smile:

I didn’t expect you to reply so quickly xD