function player_service.init()
local function plrRemoving(plr: Player)
player_service.character_cache[plr] = nil
plr:Destroy()
end
local function plrAdded(plr: Player)
plr:LoadCharacter()
local function charAdded(char: Model)
if not player_service.character_cache[plr] then
player_service.assignUniform(plr, char)
end
local hum = char:FindFirstChild("Humanoid") :: Humanoid
hum.Died:Connect(function()
task.delay(players.RespawnTime, function()
local starterCharacter = player_service.character_cache[plr]:Clone()
plr.Character = starterCharacter
starterCharacter.Parent = workspace
end)
end)
end
--[[local function charRemoving(char: Model)
local starterCharacter = player_service.character_cache[plr]:Clone()
plr.Character = starterCharacter
starterCharacter.Parent = workspace
end]]
charAdded(plr.Character or plr.CharacterAdded:Wait())
plr.CharacterAdded:Connect(charAdded)
end
players.PlayerAdded:Connect(plrAdded)
for _, player in pairs(players:GetPlayers()) do
task.spawn(plrAdded, player)
end
players.PlayerRemoving:Connect(plrRemoving)
end
I’ve just commented out the characterremoving function because that causes CharacterAdded to be called recursively if i call it