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

is it NOT respawning the character?

20:29:58.101 ServerScriptService.Respawn:10: invalid argument #1 to ‘insert’ (table expected, got string) - Server - Respawn:10
20:29:58.101 Stack Begin - Studio
20:29:58.101 Script ‘ServerScriptService.Respawn’, Line 10 - Studio - Respawn:10
20:29:58.102 Stack End - Studio

apologies for my stupidity, swap both variables:

table.insert(YourTable, Player.Name)

like this?

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

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

	local RandomPlayer = math.random(YourTable, 1)
	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)

yes and

why do you have RandomPlayer math.random() like that? swap both variables and make sure to add a hashtag # right before YourTable in the function

20:37:16.357 ServerScriptService.Respawn:14: invalid argument #1 to ‘random’ (number expected, got table) - Server - Respawn:14
20:37:16.357 Stack Begin - Studio
20:37:16.357 Script ‘ServerScriptService.Respawn’, Line 14 - Studio - Respawn:14
20:37:16.357 Stack End - Studio

send me the code
asfojhijdfhasd

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

		if Humanoid.Health > 0 then
			table.insert(YourTable, Player.Name)
		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)
local RandomPlayer = YourTable[math.random(1, #YourTable)]

it did not respawn the player but no errors

where are you handling the respawn function

oh yea i’m adding that right now lol

1 Like

so it spawns’ the player back at the SpawnLocation

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

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

	local RandomPlayer = YourTable[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
			plr:LoadCharacter()
			plr.Character:FindFirstChild("Humanoid").Health = 100
			wait(2)
			MyHRP.CFrame = RandomHRP.CFrame
		end
	end
end)

can u like show a video of what is happening i’m not exactly sure what’s causing this

External Media

sdjfhsdhfs

can u just post it on gyazo i don’t wanna download any files

what’s that?
gkjsdjfjsfjhsdjfhjsdf

i’m using streamable right now

website where u can upload videos u can also use streamable, just send link here

External Media

robloxbeabhwe