How to pick an argument of one function to use on another (Question)

Ok so this is my code:

[LUA]function test(ply) // <— “ply” is the argument I want to use in the timer below

    timer.Simple(5,function(ply) // &lt;--- Clearly this is not the way you transport an argument because it returns nil below

	if ( (SV_DATABASE:Query("SELECT hp FROM hp_pdata WHERE steam =  '"..ply:SteamID().."';")) ) then
	    code code code
                code code code
	end
	
end)

end
hook.Add(“PlayerInitialSpawn”,“playerinispawntest”, test)[/LUA]

I wrote some comments on the code so it’s easier for you to understand my problem.

Usually any variables contained within the function that runs whatever other function get transferred without you needing to do anything
My guess is that even outside the timer, ply might not be valid (for some reason)

ply is valid outside the function, i just tested that before posting my problem

You don’t need to do anything special. Simply remove it from the timer’s parameters and it will work.

You should also use IsValid( ply ) in the timer to check if the player is still valid, as 5 seconds later they could become invalid (removed, dead, etc.).

A dead player is still usable (you can still get their steam ID and all that)… although yeah, if they leave the server or something they’ll be invalid

with [LUA]If IsValid(ply)[/LUA]
and without the “ply” insine the timer it works, Thanks guys