Skip to content

Getting started | Local player variables

Andrzej edited this page Oct 18, 2025 · 3 revisions

Why use local player variables?

While global variables are useful, they can sometimes lead to unexpected behavior in your scripts. Local player variables offer more control and predictability, making your scripts more robust.

How do local variables differ from global ones?

  1. They hold a snapshot of players provided. They won't automatically update, even when made from a global variable.
  2. They're accessible only in the script in which they were created.
  3. You can freely add or remove players from them.

How to create a local player variable?

Important

  • Variable name must start with a lowercase letter
  • Variable name can only be made up of letters and numbers
✅ @myPlayers
✅ @scp999
❌ @Idiot
❌ @999
❌ @i_love_vars

1) Use an existing global player variable

@myLocalVar = @scpPlayers

This will create @myLocalVar with the same players that @scpPlayers has in that moment!

2) Make an empty variable using ()

@myLocalVar = ()

Useful for adding players manually using a custom system.

3) Get a player value from a method

@myLocalVar = JoinPlayers @classDPlayers @scientistPlayers

This will get the player value from the JoinPlayers method.

The use of methods as values will be explained later down the tutorial series. Don't worry about it for now, we will be coming back to this.

Important

Some local variables are provided to you automatically for ease of use, most importantly:

The @sender variable

This variable always contains 1 player, the person who ran the script.

This does NOT happen if the script was ran from e.g. the server console - keep this in mind!

Use case for local variables

Global variables changing values mid script

  GiveItem @scpPlayers Radio
  Wait 1s
❗ DestroyItem @scpPlayers Radio

The issue presented here, where @scpPlayers can change its value because of the Wait 1s method can be remedied with local variables.

   @playersGivenRadio = @scpPlayers

   GiveItem @playersGivenRadio Radio
   Wait 1s
👍 DestroyItem @playersGivenRadio Radio