How can i find a index with a index?

  1. What do you want to achieve?

Well firstly, i have a module script with a index of 100 tables which contains 3 diffrent indexes for a randomies color

  1. What is the issue?

I can’t seem to figure out how i can find the table within the table, beacuse it always prints out as nil
I did try to search somewhere else but I could not find any helpfull articles

Module script

local Colors= {}

for Stage = 1, 100, 1 do
	local a = {math.random(0,255), math.random(0,255), math.random(0,255)}
	table.insert(Colors,a)
	wait()
end
print(Colors)

return Colors

This prints out something like this for an example:

[1] = {
   [1] = 21
   [2] = 212
   [3] = 92
}

The main script:

local Colors = require(script.ModuleScript)
local CollectionService = game:GetService("CollectionService")

local db = true

while wait(.1) do
	
	local TaggedParts = CollectionService:GetTagged("TaggedParts")
	
	for _, TaggedPart in ipairs(TaggedParts) do

		local CurrentPart = TaggedPart

		CurrentPart.Touched:Connect(function(hit)

			if db == true then

				local Stage = CurrentPart:FindFirstChild("Stage")
				local HitStage = hit:FindFirstChild("Stage")

				if hit.Name == "Part" then	

					if CurrentPart.Stage.Value == HitStage.Value then
						local part = Instance.new("Part", workspace)
						local StageVal = Instance.new("NumberValue", part)
						StageVal.Name = "Stage"
						part.Material = Enum.Material.SmoothPlastic
						CollectionService:AddTag(part, "TaggedParts")
						local Drag = Instance.new("DragDetector", part)
						Drag.DragStyle = Enum.DragDetectorDragStyle.TranslateViewPlane
						Drag.ResponseStyle = Enum.DragDetectorResponseStyle.Geometric
						StageVal.Value = TaggedPart.Stage.Value + 1
						local StageColor = Colors[StageVal]
						**part.Color = Color3.fromRGB(StageColor[1],StageColor[2],StageColor[3])**
						CurrentPart:Destroy()
						hit:Destroy()
						part.Position = CurrentPart.Position
						db = false
						wait(.2)
						db = true
					end
				end	

			end

		end)

	end
	
end

The part which i set the part.Color i can’t figure it out

2 Likes

I immediately noticed you aren’t passing a number but rather an instance as index for your Colors table.

‘StageVal’ is an instance, you’d have to do:
local StageColor = Colors[StageVal.Value]

2 Likes

That fixed it all, i am feel so silly, tysm!

1 Like

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