I'm not sure why you keep trying to put 'target_ply' as an argument to forceSpec. It seems you don't understand how arguments work in Lua. I will try to explain, but I also suggest you read the section on functions in
Programming in Lua (
https://www.lua.org/pil/5.html).
Function declarations consist of three things: a name, a list of parameters, and a body.
The name is simply how you refer to and call the function. In your case, the name is 'forceSpec'.
The parameters are a list of 'slots' that can be assigned values via passing arguments to the function. In the function's code, these parameters are initialized as local variables and thus their values can be accessed.
The body is simply the code to be run when the function is called.
Here's an example:
Defining a function:
myFunction( parameter1, parameter2, parameter3 )
print( parameter2 ) -- we can access the parameters as local functions
end
Calling a function:
myFunction( "value1", "value2", "value3" )
Output:
value2Your forceSpec function has one parameter, target_ply. When you call the function, you should call it with a player argument, that is put a player object within the parentheses.
Example:
forceSpec( myPlayerObject )
I assume you want to be calling this on the player who is AFK, so within your cafk function just create your timer and pass target_ply to forceSpec. In this case it will work because target_ply is defined in that scope, and is a valid player.