I need to know why this isn’t working. These values are just placeholders, and are meant to be calculated inside of the function.
The intention of this code snippet is for the CanAttack and Player variables to be set by the return values of the function, basically like the picture below, just without actually creating a named function.
You’re attempting to assign a function value to two separate variables, in Lua functions are recognised as first class values so this won’t run the function and assign the returned values to the variables it’ll just attempt to assign the function itself to the two variables.
There’s a minor difference, after declaring local function Foo, you can access Foo as an upvalue inside the function, meanwhile you can’t in local Foo = function for obvious reasons, instead, local function Foo is the same as local Foo; Foo = function.
For the main question, even though it has been explained why, if you still want to use an anonymous function for whatever reason, you can actually get the anonymous function in parantheses and call it afterwards.
local CanAttack, Player = (function()
return true, "No"
end)()
-- CanAttack = true; Player = 'No'