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

Can someone explain the select function in this case?

Asked by
M39a9am3R 3210 Moderation Voter Community Moderator
9 years ago

I was wondering if someone could explain the select function in this case? I copied this script from Kohl's Anti Exploit from his Scripth account, and I was wondering if I am on the right track with my theory.

if not select(2, pcall(game.Workspace.GetRealPhysicsFPS)):match("GetRealPhysicsFPS") or
    game.Players.LocalPlayer.Parent ~= game.Players or
    not pcall(function() game.Players.LocalPlayer.Archivable = true end) or
    pcall(function() game.Players.LocalPlayer.RobloxLocked = true end) then
    report("Attempted Nil, Attempted Speed Hack Bypass or RobloxLocked") break
end

My theory is that if two of the things in the select arguments is true, then the script will ban you. I am wondering if someone can confirm this theory, and explain the select function more in depth than what the Wiki gives.

If index is a number, returns all arguments after argument number index. Otherwise, index must be the string "#", and select returns the total number of extra arguments it received.

1 answer

Log in to vote
1
Answered by 9 years ago

When the first argument given to the select function is a number it returns all arguments after that index. So if I pass the number 4 into the function it will return all the arguments after number 4. So this code would return "Argument 5" and "Argument 6" in a tuple.

select(4,"Argument 2","Argument 3","Argument 4","Argument 5", "Argument 6")

And this code would return the arguments 2 through 6:

select(1,"Argument 2","Argument 3","Argument 4","Argument 5", "Argument 6")

When you pass the string "#" as the first argument it returns the number of arguments excluding the first argument. This would return 3 as there is 3 additional arguments.

select("#",65,5,5,)

In context:

select(2, pcall(game.Workspace.GetRealPhysicsFPS))

He is using the pcallfunction to call the function game.Workspace.GetRealPhysicsFPS. pcall returns two arguments: a function and an error.

So that is equivalent to:

select(2, func,error)

The select function returns the error because it is after the second index.

The match method is then used to see if GetRealPhysicsFPS is in the error message so he knows if it returned an error and not an empty string.

This code could be rewritten as:

local func,err = pcall(game.Workspace.GetRealPhysicsFPS)

if not err:match("GetRealPhysicsFPS") then --Makes sure that the pcall did not return an error.

end
0
Oh, I see it now. I forgot there were two )'s after the GetRealPhysicsFPS. Thank you. M39a9am3R 3210 — 9y
Ad

Answer this question