Unable to assign property SoundId. Content expected, got table

I would like to find out how to fix that error: Unable to assign property SoundId. Content expected, got table

Its a ModuleScript inside ReplicatedStorage

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
2 Likes

Seems that sound.id is not a string, its a table, try printing it or do checks:

warn(sound.id) -- print the content
-- or
warn("is this a string?:", typeof(sound.id)) -- check content type
1 Like

For us to better debug this we need the code of the playFireSound and playAudio functions that is stored inside your audioHandler module.

1 Like
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```
1 Like

Hi there,

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.

From your playSound function:

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)

From your audioHandler:

	if distance > 300 then
		sound.SoundId = audio.dist -- {500, 2000}
	elseif distance < 300 and distance > 5 then
		sound.SoundId = audio.tp
	end

I’m assuming you meant to set the distance values to sound.RollOffMinDistance or sound.RollOffMaxDistance instead?

3 Likes