Storing variables on players?

This is something I have never asked about because it feels like the most basic thing in Lua and I’d be an idiot not knowing how to do it. But I have looked through other peoples scripts, searched everywhere and tried doing this myself hundreds of times and never succeeded in making it work. I would be so thankful if someone could help me with this. :slight_smile:

What I’m currently trying to do is making the key T enable thirdperson for the one who presses it without spamming it due to input.IsKeyDown. Here is the current(unfunctional) code for it.

local ply = LocalPlayer()

local ply.Keylock = false
function Buttons_USED()
     if not ply.Keylock then
          if input.IsKeyDown(KEY_T) then
               ply.Keylock = true

You might wanna try using input.WasKeyPresses instead

Or even better use a hook designed exactly for this purpose.


This function only works in Move hooks, and will detect key presses even in main menu or when a typing in a text field.

[editline]31st July 2017[/editline]

Thanks, this worked.
Althought my main reason for this thread was to actually learn how to store variables per player and I still need help with that.

Exactly how you’re using them, however you can’t put “local” in front of it like you have done on line 3.

Since this is clientside, the server won’t be able to see the variable on the player. And there isn’t much value in storing a variable on the localplayer entity, you can localize it as a normal variable instead

Thanks guys! :slight_smile: