Respawn script won't work

Basically, my game is based on TF2. You can select your class and play as it. When you die, you either wait until respawn or change class. My problem is, the character won’t respawn.
Script “Respawn”, ServerScriptService

game.Players.PlayerAdded:Connect(function(plr)
	plr:LoadCharacter()
	local hum = plr.Character:FindFirstChildOfClass("Humanoid")
	plr.CharacterAdded:Connect(function(addedCharacter)
		hum = addedCharacter:FindFirstChildOfClass("Humanoid")
	end)
	hum.Died:Connect(function()
		local class = plr:FindFirstChild("Class").Value
		if class then
			local classCharacter = game.ReplicatedStorage.Characters:FindFirstChild(class)
			local classInventory = game.ReplicatedStorage.Weapons:FindFirstChild(class)
			wait(3)
			local char = classCharacter:Clone()
			char.Name = plr.Name
			plr.Character = char
			char.HumanoidRootPart.Position = plr.TeamColor == BrickColor.new("Really blue") and workspace.Map.bluSpawn.Position or workspace.Map.redSpawn.Position
			char.Parent = workspace
			for _,v in pairs(classInventory:GetChildren()) do
				if v:IsA("Tool") or v:IsA("HopperBin") then
					v:Clone().Parent = plr.Backpack
				end
			end
		end
	end)
end)

When i used CharacterRemoving, it worked with a bug: once i selected a class, i respawned forever.
Tell me if there is a way for humanoid.Died to work. HealthChanged will make it glitchy. btw output is empty

Yes, you have to detect when the player’s humanoid dies in the player added connection. To load the character, you need to use the :LoadCharacter() function

I read through that script and I feel like it makes things way too complicated.
You can just disable “CharacterAutoLoads” on Players and then use player:LoadCharacter() to load the character.

You can toggle whatever screen u need to in the PlayerGui when the player dies, and then use a RemoteEvent to connect to the server and call loadcharacter from there.

when i disabled characterautoloads i had to add a script that enables the GUI, and it added it every time i spawned, for some reason

also about loadcharacter, check the start of the script

figured out i had an event that spawns you with a chosen class, so i did it through a local script

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.