Why does this sometimes not function fully?

This is like random, it’ll sometimes print all the way through, sometimes print halfway, sometimes only the first one prints. I’m confused.

game.Players.PlayerRemoving:Connect(function(plr)
	print'mhm'
	local key = 'notsus-'..plr.UserId
	print'ahhh'
	local gd = ds:GetAsync(key)
	print'ooo'
	local data = game.ServerStorage.Data:FindFirstChild(plr.Name..'DF')
	print'please'
	if data then
		print'yeah'
		local dts = 
		{data.Level.Value,data.XP.Value,data.NXP.Value,data.Statpoint.Value,data.Attack.Value
		,data.Technique.Value,data.Force.Value,data.SaberPos.Value,data.SaberHilt.Value
		,data.SaberColor1.Value,data.SaberColor2.Value,data.SaberColor3.Value,data.PC1.Value,data.PC2.Value,data.PC3.Value}
		ds:SetAsync(key,dts)
		print'why..?'
		data:Destroy()
	else
		print'no'
	end
end)

The problem is that the server shuts down before the function has a chance to finish. Try using BindToClose to delay the server closing. Something like this should work:

game:GetService("Players").PlayerRemoving:Connect(function(player)
-- save stuff as normal
end)

game:BindToClose(function() wait(30) end)
3 Likes