Attemtping to index nil with transparency

I want to make it so every 2 rounds, 1 more plate dissapears and for some reason it breaks after the first time:

	for i = 1, script.Parent.Difficulty.Value do
		local randomint = math.random(1, 4)
		local selected = colors[randomint]
		selected.Transparency = 1 -- Line 78 where the error fires
		selected.CanCollide = false
		table.remove(colors, randomint)
		randomint = nil
		selected = nil
	end

Here is the error:
image

1 Like

We should know what does the ‘colors’ table contains in order to resolve the issue. Also tell us what type of Instance is picked from table (Part, Model, Value etc.).

local colors = {script.Parent.Blue, script.Parent.Green, script.Parent.Red, script.Parent.Yellow}

Try this:

for i = 1, script.Parent.Difficulty.Value do
		local randomint = math.random(1, 4)
		local selected = colors:GetChildren()[randomint]
		selected.Transparency = 1 -- Line 78 where the error fires
		selected.CanCollide = false
		table.remove(colors, randomint)
		randomint = nil
		selected = nil
	end

Hey guys awesome script solver here I fixed it by adding a wait() @hestolemyrice this is where u comment

yes
wait whats, whats that “try using :heart: instead?”