Here is the script I used:
local players = game:GetService("Players") local debounce = true script.Parent.Touched:Connect(function(hit) if debounce then if hit.Parent:FindFirstChild("Humanoid") then debounce = false local plr = players:GetPlayerFromCharacter(hit.Parent) local timeBefore = tick() for i = 1, 1000 do print(plr.Name) end local timeAfter = tick() - timeBefore local timeBeforeTwo = tick() local plrName = plr.Name for i = 1, 1000 do print(plrName) end local timeAfterTwo = tick() - timeBeforeTwo print("without variable is: "..timeAfter) print("with variable is: "..timeAfterTwo) wait(5) debounce = true end end end)
Here is are the results:
without variable is: 0.084712982177734 with variable is: 0.063939332962036 without variable is: 0.084455728530884 with variable is: 0.062870502471924 without variable is: 0.085661888122559 with variable is: 0.062398672103882 without variable is: 0.079595565795898 with variable is: 0.06275749206543 without variable is: 0.083762168884277 with variable is: 0.063457012176514 without variable is: 0.080082178115845 with variable is: 0.06156849861145 without variable is: 0.072998523712158 with variable is: 0.063893556594849 without variable is: 0.077476978302002 with variable is: 0.062778949737549 without variable is: 0.083955049514771 with variable is: 0.062814712524414 without variable is: 0.082892179489136 with variable is: 0.062796592712402
Here are the averages:
Without the variable resulted in an average of: 0.0815593242645264 With the variable resulted in an average of: 0.062927532196045
You can round them if you like. Here is a link: https://scriptinghelpers.org/questions/65479/is-it-more-efficient-to-use-a-variable-or-to-access-the-property-each-time to the reason I did this test. I also did this in order to show how a test should be done in light of the recent discussion: https://forum.scriptinghelpers.org/topic/531/while-true-do-while-wait-do Hope you guys find this interesting. If you have any comments please post them. I would love to know what you think. Have a great day scripting!
Quick Edit/Note: My computer has an i7 core and the test was performed in studio play mode. Who knows what the results might be on a slower computer and on an actual server.