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
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)