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

Why does this generate two sounds?

Asked by
Azenix 1
9 years ago

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

Log in to vote
1
Answered by 9 years ago

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

Ad

Answer this question