Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What does #permission mean in this script?

Asked by
Yeevivor4 155
10 years ago
for i = 1,#permission do 
if (string.upper(name) == string.upper(permission[i])) then return true end 
end 

I am a beginning scripter and I just encountered a Card Door Model that I searched and it had this. I understand the rest but this is the part where I don't understand. Any help?

3 answers

Log in to vote
2
Answered by
Kratos232 105
10 years ago

the "for i =" is a basic for loop that is used to do things multiple times. For example, if you wanted to do something 4 times you could do this:

for i = 1, 4 do
print(i)
end

You don't need to use for i, you could use for x, or even a work like for Childs = 1, 3 do. And you can even do for i = 1, 6, 2 do, but I don't wanna explain that now.

permission is a Table, and #permission is similar to string.len() except you use it to find how many values are in a table. For example, this would print how many Players are in the Server:

local AllPlayers = Game.Players:GetPlayers()

print(#AllPlayers)

And the for i = 1, #permission is similar to for i, v in pairs(Something:GetChildren()) do except it goes through a table. An example of using it in a simple script that kicks anyone called "Kratos232"

local Players = Game.Players:GetPlayers() -- Makes a table of all the players
local Name = "Kratos232" -- Person's name you want to kick

for x = 1, #Players do -- Scans through table using for loop.
if Players[x].Name:lower() == Name:lower() then -- Checks each player in the table if there name == Name(The Variable)
Players[x]:Kick() -- Kicks if their Name is Name.
else -- Else.
print("The Player " .. Players[x].Name .. " is not " .. Name) -- If they're safe it prints "The Player (NAME) is not Name(The Variable)".
end -- End. If you didn't know this part it'd be disgraceful...

Well, this was a giant answer, and I bet most of it was useless. Well, I hope some of it helped... Bye!

  • Kratos232

P.S I prefer to use for x = 1, Something do, because "i" is overused.

Ad
Log in to vote
4
Answered by 10 years ago

#permission is the syntax to get the length of a table. permission is a table, so #permission will return how many values are in that table.

Log in to vote
-5
Answered by 10 years ago

Permission is a table. It is calling the table named permission into the "for loop".

Answer this question