I want to refer to a table of properties when editing a part's size, shape, etc

I have this snippet of code:

for i, v in pairs(path:GetWaypoints()) do
	humanoid:MoveTo(v.Position)
	humanoid.MoveToFinished:Wait()
		
	local cylinder = Instance.new("Part", visualpath)
	cylinder.Shape = "Cylinder"
	cylinder.Size = Vector3.new(0.5, 1, 1)
	cylinder.Orientation = Vector3.new(0, 0, 90)
	cylinder.Color = Color3.new(1,1,1)
	cylinder.Material =  Enum.Material.Neon
	cylinder.Anchored = true
	cylinder.CanCollide = false
	cylinder.Position = v.Position + Vector3.new(0, 1, 0)
	debris:AddItem(cylinder, 2)
end

The code works as expected, but it looks really unorganised in my script since it takes up a large block of space in my code. I would preferably have it in a ModuleScript or if i needed to, table of properties at the start but I’m not sure how to do this. This includes the Debris, but I’m not sure if that is possible since I have not seen a solution to this yet. I would be really grateful if someone could help me with this, thank you!

2 Likes

something like this should work:

EDITED SOME STUFF
EDITED AGAIN

local Properties = {
	["Shape"] = "Cylinder",
	["Size"] = Vector3.new(0.5, 1, 1),
	["Orientation"] = Vector3.new(0, 0, 90), 
	["Function"] = function(...) --// make sure the name contains Function
		debris:AddItem(..., 2)
	end,
}

local cylinder = Instance.new("Part", visualpath)
for i,v in pairs(Properties) do 
	if (string.find(i, "Function")) then 
		Properties[i](cylinder)
	else
		cylinder[i] = v
	end
end
1 Like

Thank you! This worked perfectly (after some modifications)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.