New at Lua, need help to get me started.

So I started coding with Lua and GMOD yesterday. I do know what variables are, and all of that stuff (I’ve coded before), so no need to explain that. I’m new at Lua though, and these may be like REALLY simple solutions, but I need to get more familiar with the language and how to use it.

The problem is that, I’ve never coded with server side and client side, so I’m not sure how to do when doing stuff like this:

You can only change certain things on the server side, and I’m wondering how to implement a stamina system. I don’t know how to call on the player from the server side.
I’ve tried:

  1. ply = LocalPlayer() (clientside script), which leads me to the problem: “function arguments expected near ‘=’”. So, basically, I can’t use ply:stamina for example. How do I refer to the player?

1.5 If I somehow knew how to refer to the player/players, would it select ALL the players or just a client who for example like upgrade the stamina, or something like that. If I use localplayer, does it only select that player who did it?

  1. Can somebody show me how to for example write a stamina system that when if a players run the player loses stamina and when he’s out of stamina he can’t run anymore, or do any actions that require some stamina.

I know that I can maybe do like this:

if ply:KeyDown(some random key) and stamina >= 25 then
–Cast some spell idk
else
print(“You don’t have enough stamina”)
end

And for the final thing, if you have some tips for a beginner like me, I would really appreciate it if you would write some down.

Thanks in advance.

Clientside, LocalPlayer() is the client you are executing the code on and when it’s not restricted to certain players, clientside code will run on all players. Serverside code runs on the server and the server only. Then there’s shared which runs code on both the client and the server. For your purposes, you need to use hooks. Read that. The hook you would probably use is

GM:KeyPress. If you need more keys than the provided enumerations in the second argument, use

GM:PlayerButtonDown instead.

Some tips for beginners like you.

Start with small addons.

In addition to what MelonShooter said, for your question 1.5: The server is able to discern one, specific player (which you can find using

player.GetAll or using the Net Library to send a

LocalPlayer entity). Because each clientside file is added to each individual client,

LocalPlayer will return the current client, as in the client that did whatever you’re tracking.

Edit: In my opinion, a better way to check for a person’s key down would be to use a

GM:Think hook with

input.IsKeyDown to check for the key you want.

So, basically, I just need to use hooks then? I don’t need to do this:
ply:stamina + 50
or
stamina + 50 ?
or
player.GetAll():stamina ?

I don’t think you understand what the colon does.

Totally not being biased or anything, this thread will be great for you

From the thread - Server/Client meaning, List of GLua “challenges” to familiarize with the language, Understanding Lua Errors