Respawn script that will respawn the player at a random player that is alive

You can write your topic however you want, but you need to answer these questions:

  1. Make a respawn script that will respawn the player at a random player that is alive

  2. It respawns the player but i don’t know how to respawn the player at a random player that is alive

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

ReplicatedStorage.Respawn.OnServerEvent:Connect(function(player)
		player:LoadCharacter()
end)

If you know how to please do so and thanks!

2 Likes

if i understood you correctly, you want to respawn a dead player infront of another player that is alive. you could keep all alive players inside of a table (and remove ones that are dead from the table) and use math.random() to get a random player from that table. then get the character from the chosen player to get its position. get it?

1 Like

Yep that what i would like

Roblox dumb min text thing

1 Like

the issue is i don’t really know how to do that…

1 Like
for i, Player in pairsPlayers:GetPlayers do 
   local Character = Player.Character
   local Humanoid = Character:FindFirstChild("Humanoid")

   if Humanoid.Health > 0 then
   table.insert(Player.Name, YourTable) -- Checks for any alive player
end

function Respawn(MyPlayer) -- Your player
    local RandomPlayer = math.random(1, #YourTable)
    local MyCharacter = MyPlayer.Character
    local MyHRP = MyCharacter.HumanoidRootPart

for i, Player in pairsPlayers:GetPlayers do
      if Player.Name == RandomPlayer then
          local Character = Player.Character
          local Humanoid = Character:FindFirstChild("Humanoid")

          local RandomHRP = Character.HumanoidRootPart
          MyHRP.CFrame = RandomHRP.CFrame -- Transport the player to the alive player
      end
   end
end

just the sample. i haven’t really tried this out so tell me if something doesn’t work
implement this however you want

I will give it a try right now.

uhhhh

local rep = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

rep.Respawn.OnServerEvent:Connect(function(plr)
	for i, Player in ipairs(Players:GetPlayers())  do 
		local Character = Player.Character
		local Humanoid = Character:FindFirstChild("Humanoid")
		local YourTable = {}

		if Humanoid.Health > 0 then
			table.insert(Player.Name, YourTable)
		end

		local function Respawn(MyPlayer)
			local RandomPlayer = math.random(1, #YourTable)
			local MyCharacter = MyPlayer.Character
			local MyHRP = MyCharacter.HumanoidRootPart

			for i, Player in ipairs(Players:GetPlayers())  do
				if Player.Name == RandomPlayer then
					
					local Character = Player.Character
					local Humanoid = Character:FindFirstChild("Humanoid")

					local RandomHRP = Character.HumanoidRootPart
					MyHRP.CFrame = RandomHRP.CFrame
				end
				end
			end
		end
end)

my bad, i forgot to put the other end. does it work now?

I giving it a test right now.

hdxfhsdHfhdfhgdsf

nope it just does this

just checked your script, why did you wrap the entire thread inside

for i, Player in ipairs(Players:GetPlayers())  do 

now it will fire the Respawn() function multiple times, giving the player that “Rubberbanded” effect which exploiters get.

for i, Player in ipairs(Players:GetPlayers())  do 
		local Character = Player.Character
		local Humanoid = Character:FindFirstChild("Humanoid")
		local YourTable = {}

		if Humanoid.Health > 0 then
			table.insert(Player.Name, YourTable)
		end
end
		
			local RandomPlayer = math.random(1, #YourTable)
			local MyCharacter = MyPlayer.Character
			local MyHRP = MyCharacter.HumanoidRootPart

			for i, Player in ipairs(Players:GetPlayers())  do
				if Player.Name == RandomPlayer then
					
					local Character = Player.Character
					local Humanoid = Character:FindFirstChild("Humanoid")

					local RandomHRP = Character.HumanoidRootPart
					MyHRP.CFrame = RandomHRP.CFrame
				end
			end

btw u wont need the “local function Respawn(MyPlayer)” anymore since it’s in an OnServerEvent there is no need of making another function

something’s up with “local YourTable = {}”

local rep = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

rep.Respawn.OnServerEvent:Connect(function(plr)
	for i, Player in ipairs(Players:GetPlayers())  do 
		local Character = Player.Character
		local Humanoid = Character:FindFirstChild("Humanoid")
		local YourTable = {}

		if Humanoid.Health > 0 then
			table.insert(Player.Name, YourTable)
		end
	end

	local RandomPlayer = math.random(1, #YourTable)
	local MyCharacter = plr.Character
	local MyHRP = MyCharacter.HumanoidRootPart

	for i, Player in ipairs(Players:GetPlayers())  do
		if Player.Name == RandomPlayer then

			local Character = Player.Character
			local Humanoid = Character:FindFirstChild("Humanoid")

			local RandomHRP = Character.HumanoidRootPart
			MyHRP.CFrame = RandomHRP.CFrame
		end
	end
end)

what exactly is up with the table? i need to know so i can assist u better

place variable YourTable outside of for i, Player loop, that way any thread can access it.

or like this?

1 Like

place it on the beginning of the OnServerEvent function or literally anywhere on the script just above those threads :man_facepalming:

just does this