#Sound not playing properly

1 messages · Page 1 of 1 (latest)

gaunt rock
#

The shooting sound seems to not work properly, it's playing 2 times instead of 3 times in a row. I've been researching for a while but I can't find any fix to it.

Ability Audio Snippet Code:

for i = 1, 3 do 
        task.delay(0.25 * i, function()
            _shared.playAnimation(Character, ShootAnimation)
            _shared.playGunShot(Character) 
            _shared.Fire(Character, ABILITY_NAME, ABILITY_OWNER)
        end)
    end

Client Code:

local function newSound(ID: string | number | Sound, Position: Vector3 | BasePart | any, volume: number?, ForceClientSide : boolean?)
    if ForceClientSide then
        Networking:FireAllClientConnection("PlaySound", "UREMOTE_EVENT", ID, Position, volume)
        return
    end
    
    local sound = typeof(ID) == "Instance" and ID:IsA("Sound") and ID:Clone() or Instance.new('Sound') do 
        sound.SoundGroup = SFXGroup
        if not (typeof(ID) == "Instance") then 
            sound.SoundId = `rbxassetid://{tostring(ID):match("%d+")}`
        end
    end

    local container 
        
    if typeof(Position) == "Vector3" then
        container = createSoundContainer(CFrame.new(Position), true)
        container.Parent = Effects
        sound.Parent = container
    elseif typeof(Position) == "Instance" then
        sound.Parent = Position
    end
    
    for Config : string, Value : string | number in CONFIG :: any do
        (sound:: any)[Config] = Value 
    end
    
    sound.Volume = volume or sound.Volume + 2
    sound.SoundGroup = SFXGroup
    
    if not sound.IsLoaded then
        task.spawn(function()
            sound.Loaded:Wait()
            if sound.Parent then
                sound:Play()
            end
        end)
    else
        sound:Play()
    end
    
    task.delay((sound.TimeLength or 5) + 1, function()
        sound:Destroy()

        if container and #container:GetChildren() == 0 then
            container:Destroy()
        end
    end)
end