This code is some test code for a level loader (to prevent one very long loading sequence, and to improve performance).
--[[DOCUMENTATION
Program gets [x], [y], [z] coords from array and places object.
For the purpose of this script, a simple [Part] is used (game.ReplicatedStorage.Part)
]]
local xCoordinates = {10, 13, 15, 17}
local yCoordinates = {10, 11, 12, 13}
local zCoordinates = {10, 13, 15, 17}
local itemID = 1 --Not important at the moment
for i = 1, #xCoordinates do
local xCoord = xCoordinates[i]
local yCoord = yCoordinates[i]
local zCoord = zCoordinates[i]
if itemID == 1 then
item = game.ReplicatedStorage.Part
end
local clonedObject = item:Clone()
clonedObject.Position = Vector3.new(xCoord, yCoord, zCoord) --sets position
clonedObject.Anchored = true
clonedObject.Parent = game.Workspace["Level 0"] --Parents the object to a folder named “Level 0”
print("Moved object to [x]: " .. xCoord)
print("Moved object to [y]: " .. yCoord)
print("Moved object to [z]: " .. zCoord)
end
itemID is used to differentiate between multiple models. (I used integers because that way there is less room for human error in spelling w/ strings).
How can I improve this script (performance, readability etc)?