Invalid argument #2 (string expected, got number)

Heyo! Currently struggling with a script that returns a table including all of the BaseParts in workspace & their transparencies. Been looking for a possible solution to this for a while, but to no avail. Any help would be appreciated :pray:

local parts = {}
for index, part in pairs(workspace:GetDescendants()) do
	if part:IsA("BasePart") then
		part[index] = {part, "Transparency|1|"..tostring(part.Transparency)} --// error is on this line
	end
end
return parts

Transparency is a number value, not a string that contains numeric values.

did you mean to put part[index] instead of parts[index]? it looks like you’re trying to set a property under part named whatever index gives you.

1 Like

Yep… this was what was breaking the script :man_facepalming:
A solid hour of time was spent looking for bugs that didn’t exist… Super proud of myself :smiley:

1 Like

Look at the error message next time, it would’ve displayed “Attempt to index Part with nil” or “index is not a valid member of Part”.