Hello Developers,
So I tried messing around with Clickdetectors and sounds, and I came around a problem when I first clicked a button it would not play the sound, but when I did it a second time it would play the sound. So, is this a roblox glitch or is it my code? If it’s my code, how could I fix this?
Video:
Code:
game.Workspace.HealButton.ParticleEmitter.Enabled = false -- Particle Emitter thing(Shouldn't be a problem)
function onclick()
game.Workspace.HealButton.ParticleEmitter.Enabled = true -- Particle Emitter thing(Shouldn't be a problem)
workspace.HealButton.Sound.Playing = true
wait(1)
game.Workspace.HealButton.ParticleEmitter.Enabled = false -- Particle Emitter thing(Shouldn't be a problem)
end
workspace.HealButton.ClickDetector.MouseClick:Connect(onclick)
Thanks,
Ultan
You should use :Play()
instead of .Playing = true
.
2 Likes
game.Workspace.HealButton.ParticleEmitter.Enabled = false -- Particle Emitter thing(Shouldn't be a problem)
local state = false
function onclick()
if not state then
state = true
game.Workspace.HealButton.ParticleEmitter.Enabled = true -- Particle Emitter thing(Shouldn't be a problem)
workspace.HealButton.Sound:Play()
workspace.HealButton.Sound.Ended:Wait()
game.Workspace.HealButton.ParticleEmitter.Enabled = false -- Particle Emitter thing(Shouldn't be a problem)
state = false
end
end
workspace.HealButton.ClickDetector.MouseClick:Connect(onclick)
1 Like
That code doesn’t seem to work for me. It doesn’t play the sound at all. Could I be missing something?
I tried changing it out with that and it doesn’t seem to work, Could I be missing something?
Try this:
game.Workspace.HealButton.ParticleEmitter.Enabled = false -- Particle Emitter thing(Shouldn't be a problem)
function onclick()
game.Workspace.HealButton.ParticleEmitter.Enabled = true -- Particle Emitter thing(Shouldn't be a problem)
script.Parent.Sound:Play()
wait(1)
game.Workspace.HealButton.ParticleEmitter.Enabled = false -- Particle Emitter thing(Shouldn't be a problem)
end
game.workspace.HealButton.ClickDetector.MouseClick:Connect(onclick)
1 Like
Try cloning the Sound, perhaps?
local HealParticle = workspace.HealButton:WaitForChild("ParticleEmitter")
HealParticle.Enabled = false
local function OnClick()
HealParticle.Enabled = true
local SoundClone = workspace.HealButton.Sound:Clone()
SoundClone.Parent = workspace
SoundClone:Play()
SoundClone.Ended:Connect(function()
SoundClone:Destroy()
HealParticle.Enabled = false
end)
end
workspace.HealButton.ClickDetector.MouseClick:Connect(OnClick)
2 Likes