I want to add effects like sparkles to brick and when you click it, the sound will play and also sparkling. How can I do that?
01 | Brick = script.Parent |
02 | Sound = Brick.Sound |
03 | Debounce = false |
04 |
05 | function onClicked() |
06 | if not Debounce then |
07 | Debounce = true |
08 | Sound:Play() |
09 | wait(Sound.TimeLength) |
10 | Debounce = false |
11 | end |
12 | end |
13 |
14 | script.Parent.ClickDetector.MouseClick:connect(onClicked) |
Am I doing this right?
01 | sparkles = Instance.new( "Sparkles" ) |
02 | sparkles.Parent = Brick |
03 | Brick = script.Parent |
04 | Sound = Brick.Sound |
05 | Debounce = false |
06 |
07 | function onClicked() |
08 | if not Debounce then |
09 | Debounce = true |
10 | Sound:Play() |
11 | wait(Sound.TimeLength) |
12 | Debounce = false |
13 | end |
14 | end |
15 |
16 | script.Parent.ClickDetector.MouseClick:connect(onClicked) |
To make sparkles, add in:
sparkles = Instance.new("Sparkles", Brick)
Add the line before or after Sound:Play()
You are not calling the variable, so it doesn't spawn, do this:
1 | sparkles = Instance.new( "Sparkles" ) |
2 | sparkles.Parent = Brick |
Edit:
01 | c = Instance.new( "ClickDetector" ) |
02 | c.Parent = Brick |
03 | s = Instance.new( "Sparkles" ) |
04 | s.Parent = Brick |
05 | s.Enabled = false |
06 | local on = false |
07 |
08 | c.MouseClick:connect( function () |
09 | if on = = false then |
10 | on = true |
11 | s.Enabled = true |
12 | else |
13 | s.Enabled = false |
14 | on = false |
15 | end |
16 | end ) |
There is no ClickEnded event for ClickDetectors.