CharacterAdded event does not fire after pcall()

local function onPlayerAdded(player)
	local dsScope = "Player_"..player.UserId
	local dataFolder = game.ServerStorage.DataFolder:Clone()
	dataFolder.Parent = player
	local playerStandID
	local succ,err = pcall(function()
		playerStandID = sds:GetAsync(dsScope)
	if succ and not err then
		if playerStandID == nil then playerStandID = 0 end
		print(player.Name.."'s data has successfully loaded! | Stand Identifier : "..playerStandID)
		dataFolder.StandIdentifier.Value = playerStandID
	elseif not succ and err then
		warn(player.Name.."'s data has failed to load! :(")
		dataFolder.AbleToSave.Value = false
		player:Kick("Your data has failed to load! Please rejoin! If this problem persists, please contact a game developer or administrator!")

For some reason the characterAdded event does not fire, if I put it before the pcall it does, but I can’t do that because I need the data to load before the character does.
Please let me know any solutions, thanks!

That’s because GetAsync is asynchronous which means it yields the thread until it errors or is successful.

You would have to replace player.CharacterAdded:Connect(onCharacterAdded) with

onCharacterAdded(player.Character or player.CharacterAdded:Wait()
1 Like