Help with data store

I have problem understanding this success syntax:

    repeat
		success, playerData = pcall(function()
			return DataBase:GetAsync(PlayerUserId)
		end)
		Attempt += 1
		if not success then
			warn(playerData)
			task.wait(3)
		end
	until success or Attempt == 5

is it equal to

if succes then 
 playerData = pcall(function()
			return DataBase:GetAsync(PlayerUserId)
		end)
end

?
Does this syntax have a name? Is it even a lua or some roblox thing?

No, those code-blocks are not equivalent to each other. A pcall(protected call) function returns a boolean, “success” and the data received back from the pcall() function is the player’s data, “playerData”. “success” and “playerData” are both variables, being set by the returned values.
pcall() is part of lua.
These 2 pages might help you better understand what they are:

1 Like

Thank you. Another question, why we set success and playerdata to nil? Why not set success to false or not give it any value at all?

It would just be redundant to do that. False and nil would evaluate to the same thing. If you don’t give a variable a value, its nil too by default.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.