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