I don't understand what these lines of code are for (datastore, script)

Hello ! I marked the point at which I don’t understand at : " – from here to the very bottom, I don’t understand what these lines are for" in the script.
I explain, whether I put all these lines, or not, the backup is done the same way, in all the tutorials I saw, the developers put these lines (they script was often different of mine), but with my script I don’t feel that they have any interest since the PlayerRemoving performs the backup, or the automatic backup every 2 minutes that I added (or the BindToClose). Does anyone know if this is of any interest in my case? I can put the whole script if necessary (it’s a bit long)

game.Players.PlayerAdded:Connect(function(player)
	local folder = Instance.new("Folder")
	folder.Name = "Creatures"
	folder.Parent = player

	local data
	local success, errorMsg = pcall(function()
	data = DataStore:GetAsync(player.UserId)
        end)
	for _, cName in pairs(data) do
		if workspace.Creatures:FindFirstChild(cName) then
			local newval = Instance.new("BoolValue")
			newval.Name = cName
			newval.Parent = folder
        print("dataok")
		end
	end
   -- from here to the very bottom, I don't understand what these lines are for

	if success and data then
		print("hi")
	else
		print("no data")
		wait(5)
		if success and data then
			print("data21")
		else	
			wait(10)
			if success and data then
				print("data21")
			else
				wait(10)				
				if success and data then
					print("data21")
				else
					player:Kick("Your data failed to load ! We are sorry, Please rejoin")
                end	
			end  
		end 
	end

The top if statement lua if success and data then means that if the data got successfully loaded and the data is not nil then it will print hi and you can continue your code from there. Under the else however i don’t understand why they would nest so many if statements but if their data never got loaded they just get kicked. I would just opt in to load their data once in it’s own function and if it fails then i call it again for like 2 times and if it still never loads then just kick the player.

1 Like

I think I understood that these lines have absolutely no use in my case. If anyone thinks I am wrong please tell me because I am not 100% sure. Thank you

Thank you very much for these explications