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

How to detect if 1 of some buttons is pressed?

Asked by
Mokiros 135
8 years ago

For example, i have a script, which creates 10 numbered parts with ClickDetectors

for i = 1,10 do
    p = Instance.new("Part",workspace)
    p.Name = i
    p.Position = Vector3.new(0,i,0)
    c = Instance.new("ClickDetector",p)
end

And if one of those buttons is pressed, paint pressed button in blue. How do i do it?

1 answer

Log in to vote
0
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
8 years ago

ClickDetectors have a MouseClick event you can use:

for i = 1,10 do
    p = Instance.new("Part",workspace)
    p.Name = i
    p.Position = Vector3.new(0,i,0)
    c = Instance.new("ClickDetector",p)

    c.MouseClick:connect(function()
        p.BrickColor = BrickColor.new("Bright blue")
    end)

end
Ad

Answer this question