Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I reference only the clicked part in a group of parts?

So I am new to scripting and I am trying to make a very simple drawing game. I'm trying to make it so when you choose a color from given color choices, it makes whatever one part of the canvas you click on turn that color. I have attempted this in the script below (I know the script does not work). Could someone please help me fix my script, it would help me improve as a developer :).

while script.Parent.ClickDetector.MouseClick:Wait() do
	local Canvas = game.workspace.Model:GetChildren()  --Model is the canvas 

		while Canvas.ClickDetector.MouseClick:Wait() do
			if Canvas.BrickColor == BrickColor.Red() then 
			else
				Canvas.BrickColor = BrickColor.Red()
			end
		end
	end

1 answer

✓ Accepted answer

Fixed script:

	script.Parent.ClickDetector.MouseClick:Connect(function()
	    for _,Canvas in pairs(game.workspace.Model:GetChildren()) do  -- Model is the canvas
                Canvas.ClickDetector.MouseClick:Connect(function()
	            if Canvas.BrickColor == BrickColor.Red() then
	            else
	                Canvas.BrickColor = BrickColor.Red()
	            end
                  end
	        end)
	    end)

This discussion is preserved as it was. New answers, comments, and votes are closed.