Hello! I am trying to pass a colon function Inside another function without calling it. Example:
function test(func, ...)
func(...)
end
test(MarketplaceService:UserOwnsGamePassAsync, player.UserId, id) --doesn't work
test(MarketplaceService.UserOwnsGamePassAsync, player.UserId, id) --also doesn't work
How would I achieve this? I am trying to make a single function to easily pcall requests.
There’s no such thing as “colon functions”. a:b() is equivalent to a.b(a). And there’s no such thing as a:b (i.e. without the “function calling” parentheses, like in your first example).^1 So you just do
local mps = MarketplaceService
test(mps.UserOwnsGamepassAsync, mps, player.UserId, id)
This should work, but it’s not impossible that Roblox have modified the language to not allow this. I don’t have Roblox on this computer so I can’t test it, please post the errors you get if it doesn’t work.
By colon functions he’s probably referring to the colon operator which is used in functions which are typically referred to as methods and as you correctly pointed out they allow for the object through which the method was called from to be implicitly declared as an argument received by the method.
task.wait(5)
local function returnFirstPlayer(arg)
return arg:GetPlayers()[1]
end
local players = game:GetService("Players")
print(returnFirstPlayer(players))
This actually worked for me in studio and correctly printed my player instance (which prints the name).