Hey! I’m getting a ‘Maximum event re-entrancy depth exceeded for Player.CharacterAdded’ error in my output, and have no clue why. Any answers would be appreciated, thanks!
Code:
game.Players.PlayerAdded:Connect(function(plr)
local Race = Instance.new('StringValue')
Race.Name = 'Race'
Race.Parent = plr
local plrID = '231879321980398213123'..plr.UserId
local data
local success, errormessage = pcall(function()
data = charDataStore:GetAsync(plrID)
end)
if success then
if not data then
createNewCharacter(plr)
print('no data')
elseif data then
loadCharacter(plr, data)
print('data')
end
end
plr.CharacterAdded:Connect(function()
loadAfterDeath(plr)
end)
end)
function loadAfterDeath(plr)
local char = plr.Character
local Race = plr.Race
local newchar = chars[Race.Value]:Clone()
newchar:SetPrimaryPartCFrame(char.PrimaryPart.CFrame)
plr.Character = newchar
anims.Animate:Clone().Parent = newchar
newchar.Parent = workspace
char:remove()
plr.Race.Value = newchar.Name
end