self.playSound = function(name)
local sounds = self.loadedSounds[name]
if sounds then
local sound = sounds[math.random(1,#sounds)]
local pitch = sound.pitch and Math.Randomize2(sound.pitch[1], sound.pitch[2],0.01) or 1
if sound.type == "fire" or sound.type == "fire-s" then
audioHandler.playFireSound(self.weapon.RootPart.firePoint.WorldPosition, {
id = "rbxassetid://"..sound.id,
tp = "rbxassetid://"..sound.tp,
volume = sound.volume or 1,
pitch = pitch,
dist = {500, 2000},
}, false)
else
audioHandler.playAudio(self.weapon.RootPart, {
id = "rbxassetid://"..sound.id,
volume = sound.volume or 0.5,
pitch = pitch,
dist = {15, 300},
}, false)
end
end
end
local replicatedStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local runService = game:GetService("RunService")
local physicsService = game:GetService("PhysicsService")
local UIS = game:GetService("UserInputService")
local targetEvent = runService.RenderStepped
local utilities = require(replicatedStorage.Assets.Modules:FindFirstChild("Utilities"))
local thread = utilities["Thread"]
local roblox = utilities["Roblox"]
local Math = utilities["Math"]
local spring = utilities["Spring"]
local audioHandler = {}
function audioHandler.playFireSound(position,audio,isReplicated)
local attachment = Instance.new("Attachment")
attachment.WorldPosition = position
attachment.Name = "fireSoundPoint"
attachment.Parent = workspace.Terrain
local distance = (workspace.Camera.CFrame.Position - position).magnitude
local sound = Instance.new("Sound")
sound.SoundId = audio.id
if distance > 300 then
sound.SoundId = audio.dist
elseif distance < 300 and distance > 5 then
sound.SoundId = audio.tp
end
sound.Volume = audio.volume
sound.PlaybackSpeed = audio.pitch
sound.RollOffMaxDistance = audio.dist[2]
sound.RollOffMinDistance = audio.dist[1]
sound.Name = "fireSound"
sound:Play()
sound.Parent = attachment
sound.Ended:Connect(function()
game.Debris:AddItem(sound,1)
end)
if not isReplicated then
replicatedStorage.Assets.Remotes.PlayFireSound:FireServer(position,audio)
end
end
function audioHandler.playAudio(part,audio,isReplicated)
local sound = Instance.new("Sound")
sound.SoundId = audio.id
sound.Volume = audio.volume
sound.PlaybackSpeed = audio.pitch
sound.RollOffMaxDistance = audio.dist[2]
sound.RollOffMinDistance = audio.dist[1]
sound.Name = "fireSound"
sound:Play()
sound.Parent = part
sound.Ended:Connect(function()
game.Debris:AddItem(sound,1)
end)
if not isReplicated then
replicatedStorage.Assets.Remotes.PlayAudio:FireServer(part,audio)
end
end
return audioHandler```
I believe the error is apparent here considering the dist that you’re parsing onto your playFireSound function and attempting to set the sound.SoundId property to the dist array.