local success, result, Plays = pcall(handler, ReceiptInformation,player)
I saw a code like this on the wiki and i was wondering what player was
I believe this is a snippet from the a MarketplaceService article. This third argument isn't specific to a Player Object, it actually represents the argument being supplied into the function defined in the first.
This is a bit tough to grasp, however, let me try my best to explain...
The most common representations of pcalls
usually just receive a fresh function, of which we use to perform our instructions, E.g:
local Success, Response = pcall(function() print("Do something") end)
If you're unfamiliar with what this first argument is, the example above should be quite obvious, pcall()
will take the function provided and run it in what we call a try except
block within other coding languages. Essentially, it will operate the instructions in a safe environment, meaning any potential exceptions thrown will not interrupt the Lua thread.
However, with your case above, you're using a more advanced form of a pcall()
use. The structure holds itself like so: Function
, Function Family
; where it belongs to, & the argument
that will by supplied when running it.
Let's take a look at an example of this with a DataStore
, that way, we can make it a little easier to understand:
If there are no issues, Response
is the variable :GetAsync()
will return to.
local DataStoreService = game:GetService("DataStoreService") local DataStore = DataStoreService:GetDataStore("MyData") local Players = game:GetService("Players") local Data; local function GetData(Player) local Success, Response = pcall( DataStore.GetAsync, --// Function DataStore, --// Belongs to our DataStore Object Player.UserId --// Argument supplied ) if (Success) then Data = Response end end Players.PlayerAdded:Connect(GetData)
If this helped, don't forget to accept this answer!