-
Notifications
You must be signed in to change notification settings - Fork 2
Getting started | 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.
- They hold a snapshot of players provided. They won't automatically update, even when made from a global variable.
- They're accessible only in the script in which they were created.
- You can freely add or remove players from them.
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
@myLocalVar = @scpPlayers
This will create @myLocalVar with the same players that @scpPlayers has in that moment!
@myLocalVar = ()
Useful for adding players manually using a custom system.
@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:
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!
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
(These tutorials are ordered, start from the top)