So the question might seem a little weird but hear me out. Recently when I posted a question with a script attached some person commented saying something like: "Why are you using the variable plrName
instead of just doing plr.Name
each time?" Note: local plrName = plr.Name
. So I started changing my scripts to reflect what the person said. Today I was thinking and wondered if it was better to use the variable anyway. The reason: Every time you do .Name
aren't you accessing a property of player? If so, is it not more effective and efficient to store the string in a variable so you are not accessing it each time? I do think that if you just needed to use the player's name a few times, it might be more efficient to do .Name
. However, I am using it many times and want to know what the better method is. Does it even make that big of a difference in performance? Thanks!
local name = workspace.Brick.Name print(name) --> Brick workspace.Brick.Name = "Part" print(name) --> Brick print(workspace.Brick.Name) --> Part
script.Parent
is usually, as not many times does a Parent
get reassigned.They both work, but the variable one will let you put a shorter amount of code each time, plus you are writing it multiple times.
The point is I think variable is better, -DominusInfinitus (I hope this works out for you)