This script plays a sound when clicked and turns red for 10 seconds while on cooldown, how do i add it so a particleemitter is active for 5 seconds
local sound = script.Parent.Sound
local cd = false
local button = workspace.Button
local sound = script.Parent.Sound
local Green = Color3.fromRGB(0, 255, 0)
local Red = Color3.fromRGB(255, 0, 0)
function playsound()
if cd == false then
cd = true
button.Color = Red
sound:play(sound)
wait(10)
cd = false
button.Color = Green
end
end
script.Parent.ClickDetector.MouseClick:connect(playsound)
You can use something like this, I also improved your script a little bit. Add a ParticleEmmiter into the Part and set Enabled to false! Also use task.wait() instead of wait() in your scripts. task.wait() is improved and better than wait().
local ClickDetector = script.Parent.ClickDetector
local sound = script.Parent.Sound
local button = script.Parent
local sound = script.Parent.Sound
local ParticleEmitter = script.Parent.ParticleEmitter -- add one and costumize it and set Enabled to false!
local debounce = false
function playsound()
if debounce== false then
debounce = true
button.Color = Color3.fromRGB(255, 0, 0)
sound:play()
ParticleEmitter.Enabled = true
task.wait(5)
ParticleEmitter.Enabled = false
task.wait(5)
button.Color = Color3.fromRGB(0, 255, 0)
debounce = false
end
end
ClickDetector.MouseClick:Connect(playsound)
Hey, i made a small change to the script to make the particles emit from a different brick than the scripts parent, tho the sound, color change and particles dont work
llocal ClickDetector = script.Parent.ClickDetector
local sound = script.Parent.Sound
local button = script.Parent
ParticleEmitter = workspace.Engine.ParticleEmitter -- add one and costumize it and set Enabled to false!
local debounce = false
function playsound()
if debounce == false then
debounce = true
button.Color = Color3.fromRGB(255, 0, 0)
sound:play(sound)
ParticleEmitter.Enabled = true
task.wait(6)
ParticleEmitter.Enabled = false
task.wait(5)
button.Color = Color3.fromRGB(0, 255, 0)
debounce = false
end
end
ClickDetector.MouseClick:Connect(playsound)
This should work. Just make sure you’re using a Script and not a LocalScript.
local cD = script.Parent.ClickDetector;
local sound = script.Parent.Sound;
local button = script.Parent;
local particle = workspace.Engine.ParticleEmitter;
local db = false;
cD.MouseClick:Connect(function(player)
if not db then
db = true;
button.Color = Color3.fromRGB(255,0,0)
sound:Play();
particle.Enabled = true;
wait(6)
particle.Enabled = false;
wait(5)
button.Color = Color3.fromRGB(0,255,0);
db = false;
end
end)