Im working on a game where when you touch a part everyone dies but after a certain amount of time they respawn, Is there a way to respawn them after I use game.players:ClearAllChildren()
script.Parent.Touched:Connect(function(p)
if (game.Players:GetPlayerFromCharacter(p.Parent)) then
for _, player in ipairs(game.Players:GetPlayer()) do
player:LoadCharacter()
end
end
end)
Oh I just realised you did clear all children, that pretty much breaks the game as the players wont be able to respawn, replace the clear all children with the reload character
you would add a check in the for loop of what their team is
(just in case youre not sure “v” is a variable for the player)
for i,v in pairs(game.Players:GetChildren()) do
if v.Team == game:GetService("Teams").Team1 or v.Team == game:GetService("Teams").Team2 then
v:LoadCharacter() --Code in this for loop will run for every player
end
end
You are trying to delete every player which will just end up them disconnecting from the game. If you want to respawn every player use a generic for loop and run it on every player, and then use the method :LoadCharacter().
for _, player in ipairs(game.Players:GetPlayers()) do
if player.Team == game.Teams["Sans"] or v.Team == game.Teams["Chara"] then
player:LoadCharacter();
end
end
You should also be using the method :GetPlayers() on the Players service instead of :GetChildren.
Are Sans and Chara the only teams? If so, you won’t have to call an if statement and just load each of the player’s characters since judging from how you did it you’re trying to call :LoadCharacter on every player in that team.
for _, player in ipairs(game.Players:GetPlayers()) do
if player.Team == game.Teams["Sans"] then
player:LoadCharacter();
elseif player.Team == game.Teams["Chara"] then
player:LoadCharacter();
end
end
Try this one out, and see if it makes any difference. If it still doesn’t work, open the output and tell me if there are any errors.