Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does this generate two sounds?

that generates two sounds instead of one could someone please explain why or explain an way to get rid of one ps this does same thing whether i put local Sound = Instance.new("Sound")

print("SystemA Started")
Id = script.Parent.EveryThing.System.Id.NumberValue
Pitch = script.Parent.EveryThing.System.Pitch.NumberValue
Volume = script.Parent.EveryThing.System.Volume.NumberValue
Sound = Instance.new("Sound")
Sound.Name = ("SoundBa")
Sound.Parent = script.Parent
Sound.Looped = false
Sound.SoundId = "http://www.roblox.com/asset/?id="..Id.Value..""
sound.Pitch = 1
sound.Volume = 1
while true do
	wait()
	Sound.SoundId = "http://www.roblox.com/asset/?id="..Id.Value..""
	Sound.Pitch = Pitch.Value
	Sound.Volume = Volume.Value
	if script.Play.Value == true then
		script.Play.Value = false
		Sound:Stop()
		wait(1)
		Sound:Play()
	end
end

1 answer

✓ Accepted answer

Try adding an if statement to check if the sound exists first before creating it. I'm not sure if that will work, but it might do.

print("SystemA Started")
Id = script.Parent.EveryThing.System.Id.NumberValue
Pitch = script.Parent.EveryThing.System.Pitch.NumberValue
Volume = script.Parent.EveryThing.System.Volume.NumberValue

if script.Parent:FindFirstChild("SoundBa") == nil then
	Sound = Instance.new("Sound")
	Sound.Name = ("SoundBa")
	Sound.Parent = script.Parent
	Sound.Looped = false
	Sound.SoundId = "http://www.roblox.com/asset/?id="..Id.Value..""
	sound.Pitch = 1
	sound.Volume = 1
end

while wait() do
    Sound.SoundId = "http://www.roblox.com/asset/?id="..Id.Value..""
    Sound.Pitch = Pitch.Value
    Sound.Volume = Volume.Value
    if script.Play.Value == true then
        script.Play.Value = false
        Sound:Stop()
        wait(1)
        Sound:Play()
    end
end

This discussion is preserved as it was. New answers, comments, and votes are closed.