Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 2 years ago
Edited 2 years ago

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

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

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)

Ad

Answer this question