I honestly don’t know when. I always considered it unnecessary, but I keep seeing error messages saying consider changing to local, so I just thought I’d ask.
1 Like
local is use when first defining a variable. After defining the variable, local does not need to be used anymore when using the variable. If it is only a one-time use of the piece of code, consider not making it an entire variable. Here’s a code example to show you what I mean.
local Part = Instance.new("Part") -- since i'm using the variable multiple times, I have to define it using `local`
Part.Parent = game.Workspace -- you don't need to use local here, as you already defined it
Part.Size = Vector3.new(1, 1, 1)
local Part2 = Instance.new("Part") -- since I want a new part, i have to use `local` again to define it as I'm using more than once
Part2.Parent = game.Workspace -- again, don't need to use `local` when it was previously defined
Part2.Position = Vector3.new(0, 0, 0)
Instance.new("StringValue") -- i don't need to define it using `local` or even a variable, as it is only being used once
2 Likes
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.