(plr, "something")

Hello devs
My problem is simpler than it looks, whenever I go to internet tutorials about scripts, the devs use a function similar to this:
DataStore: SetAsync (Plr.UserId, information)
function Load(Chr, Plr)
I don’t know how to ask but …
–what do these parentheses mean… ?
–what are the programmer is calling when you put these parentheses?

sorry if it wasn’t clear, but I really don’t know what to think about these situations
all_TY :slight_smile:

2 Likes

plr.UserId is the key in the datastore, and information is the value.

I would recommend reading this if you need help understanding dictionaries and keys/values, because a datastore is pretty much a dictionary.

1 Like

https://education.roblox.com/en-us/resources/multiple-parameters-and-arguments---code-fundamentals

1 Like

despite knowing a little about programming I had never read this article about tables, really thanks :smiley:

For the first line of code, DataStore:SetAsync(plr.UserId, info) , since it is a proper Lua function, the two parameters HAVE to be given, it is made to take in these parameters. The first one being the key you use to set async, and the second one being what information you want to set. For the second one, it looks like a user made function called load, and the user has made it to take in two parameters. These can be used to call the function with values, an example:

function send(Name, str)
         print(Name..""..str)
end)

send("AAD232007", "how are you?") 
-- This will use that function by sending "AAD232007" as the name value in the function, and "how are you?" for the str. The function then uses these values to make a print statement so the output would be, AAD232007 how are you?

If you still don’t understand something, let me know!

1 Like

I understand what you mean, so is it like a
for i, v in pairs ?
or not?

1 Like

Sorry? What do you mean by the for loop?

1 Like

That loops through a table. The i stands for the current index or the ‘key’ while the v stands for it’s value (You can change the variables to whatever you want but they still hold the same purpose).

For example, workspace.Part.BrickColor = BrickColor.Red()
“BrickColor” would be the key while “BrickColor.Red()” would be the value.

1 Like

@AAD232007 that’s what I meant, where here is an indexer and a value

because what I really wanted to know was … what does parenthesis do in these cases?
(plr, x)
do they also through to a table?

They can do to anything. In a user made function, anything inside the parentheses is just a value supplied to the function. You can use these values to do absolutely anything, from changing a part’s color, to printing a statement.

1 Like

The parenthesis aren’t the table. They’re just used to hold the values for the function to use. You can however do this:

local function return_values(content)
  local t = {} -- a temporary blank table to hold the values

  for _, value in pairs(content) do
     -- i used "_" for the index because i'm not going to use it (optional)
     table.insert(t, value) -- this inserts the current value into the table
  end

  return table.unpack(t) -- this returns all of the values in the table
end

print(return_values { index = "value", one = "two"}) -- if your function expects a table, you can call it like this
-- prints "value", "two"
1 Like

umm, really helpfull
I think I will start to study more on this subject, thank you all for the feedback <3