Log in to vote

What does 'local script = script' actually do? [closed]

Asked by
iFlusters 355 Moderation Voter
4 years ago
Edited 4 years ago

So I was looking at Sceleratis's Addonis Core and he starts off with:

local _G = _G
local script = script
local game = game
local workspace = workspace
local getfenv = getfenv
local setfenv = setfenv
local getmetatable = getmetatable
local setmetatable = setmetatable
local math = math
local print = print
local warn = warn
local error = error
local coroutine = coroutine
local pcall = pcall
local ypcall = ypcall
local xpcall = xpcall
local select = select
local rawset = rawset
local rawget = rawget
local rawequal = rawequal
local pairs = pairs
local ipairs = ipairs
local next = next
local newproxy = newproxy
local os = os
local tick = tick
local loadstring = loadstring
local tostring = tostring
local tonumber = tonumber
local unpack = unpack
local string = string
local Instance = Instance
local type = type
local wait = wait
local require = require
local table = table
local Enum = Enum

Is there any reason for this/does it do anything?

The entire 37 lines is just a complete waste of space Perci1 4987 — 4y
No, they are not. Link150 1345 — 4y

Locked by User#19524

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

2 answers

Log in to vote
Answered by
eLunate 5136 Trusted Moderation Voter Community Moderator
4 years ago


For those of scripters who are anal about performance, a useful piece of information is that global variables are about 10x slower for each access than local variables. When you're running stuff in tight loops, or as an addon, that sort of stuff stacks up.

There's also the upvalues argument. Occasionally I will (for example) insert all of the values I'm using into locals ahead of time because then they are accessed by functions as upvalues instead of fetching them from the global environment. This avoids variable value inconsistency, as you can expect each variable to point to what it was defined as (For more information on environments, look here and refer to 5.1)

So, to those of you who thought it's for nothing, now you know better.

Log in to vote
Answered by 4 years ago

The most reasonable reason would be that it would be easier to target them or hes just lazy so he made them the same variable but in a easier way since roblox doesnt target it or auto complete it so he made those variables so roblox does target it.