Characters not reloading?

Hello! I am trying to make an artificial respawn system as I currently have a script that interferes with the normal one. When I run the game the first print statement goes off but the one inside of the while loop doesn’t. This is in a server script, DefaultRS is equal to 1, and this is not the only PlayerAdded event.

I will elaborate if needed.

game.Players.PlayerAdded:Connect(function(Player)
	print(Player.Name.." has joined!")
	print(DefaultRS)
	game.Workspace:WaitForChild(Player.Name)
	while Player.Character.Humanoid.Health <= 0 do
		print(Player.Name.." is respawning!")
		wait(DefaultRS)
		Player:LoadCharacter()
	end
end)

You can use .Died instead of that loop, like:

game:GetService('Players').PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		-- Do your own stuff here
		character:WaitForChild("Humanoid").Died:Connect(function()
			player:LoadCharacter()
		end)
	end)
end)

As for the LoadCharacter, it’s a bit touchy & I’m not sure if you can. It really depends on what you are using to prevent the player from respawning.

1 Like

After adding an if statement and modifying some other stuff it works now!

The modified script looks like this:

game:GetService('Players').PlayerAdded:Connect(function(Player)
	print(Player.Name.." has joined the game!")
	Player.CharacterAdded:Connect(function(Character)
		Character:WaitForChild("Humanoid").Died:Connect(function()
			if TSActive == false then
				wait(DefaultRS)
				print(Player.Name.." is respawning!")
				Player:LoadCharacter()
			elseif TSActive == true then
				while TSActive == true do
					wait(0.1)
				end
				wait(DefaultRS)
				print(Player.Name.." is respawning!")
				Player:LoadCharacter()
			end
		end)
	end)
end)
1 Like