Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

?Why is the script performance for a less efficient script better than the more efficient one

Efficient script Has about 2 to 4% performance

local tbl = {workspace.Part,workspace.Part1,workspace.Part2,workspace.Part3}


while wait() do
	for i,v in pairs(tbl) do
		v.Position = v.Position + Vector3.new(0,.01,0)
	end
end


Unefficient script

Has about .3 to .5 performance

local Part = game.Workspace.Part
local Part1 = game.Workspace.Part1
local Part2 = game.Workspace.Part2
local Part3 = workspace.Part3






while wait() do
	Part.Position = Part.Position +Vector3.new(0,.01,0)
	Part1.Position = Part1.Position +Vector3.new(0,.01,0)
	Part2.Position = Part2.Position +Vector3.new(0,.01,0)
	Part3.Position = Part3.Position +Vector3.new(0,.01,0)
end

From the performance statistics the Unefficient script is less laggier by almost 8x

2 comments

1

The first script is calling multiple functions. The for-loop iterator is called every loop including the instantiation pairs(tbl).

0

This was made by CntKillMe, it should help if you want to understand https://docs.google.com/document/d/1KlrlNYNfVKyvTbmJBoVODOqMJF-wTn_JbGUEm0G6RIM/edit

1 answer

not exacly sure what you mean but in the first script you are using a table to make changes to several items at once, it makes the changes like they are one thing. in the second script you dont use a table so the script have to change the position on them one by one and that takes a bit longer since they dont work as one part, atleast thats how i believe it works

1 comment

1

Wrong. The first script iterates through the table in a loop. Loops are procedural and nothing is happening 'at once'. Each script changes each part one by one.

This discussion is preserved as it was. New answers, comments, and votes are closed.