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

bad argument #3 to 'SoundId' (string expected, got nil)?

So I'm working on a sound system that only plays to one client (Yes, I'm using FilteringEnabled), and all of my sounds are inside of a modulescript. I'im using 4 scripts (including the module), here they are. (My issue is, it keeps saying what the title says and never plays)

**** If you could help that'd mean a lot, Thank you. v Module Script named "Sounds"

local SoundModule =
{
	Birds = "176132295";
	Suburbia = "176132394";
	SpringSound = "175637232";
	DingDong = "173452642";
	MessageClose = "173452663";
	ClothingEquip = "174308578";
	Warp = "173452757";
	NPCMessage = "173452617";
	NanoSummon = "171951986";
	MissionAccept = "171951946";
	MissionComplete = "171951929";
};

return SoundModule

v LocalScript inside a button just to test to see if the sound works

local RS =game:GetService("ReplicatedStorage")
local EV = RS:WaitForChild("Events")
local SE = EV:WaitForChild("SoundEvent")
local MO = RS:WaitForChild("Modules")
local S = require(MO:WaitForChild("Sounds"))

local PLR = game.Players.LocalPlayer

script.Parent.MouseButton1Click:connect(function()
	SE:FireServer(PLR,S.DingDong)
end)

v The Client Side Sound Handler

local RS =game:GetService("ReplicatedStorage")
local EV = RS:WaitForChild("Events")
local SE = EV:WaitForChild("SoundEvent")
local MO = RS:WaitForChild("Modules")
local SO = script.Parent:WaitForChild("Sound")

SE.OnClientEvent:connect(function(PLR,id)
	SO.SoundId = id
	SO:Play()
end)

v And the ServerSideHandler in Workspace

local RS =game:GetService("ReplicatedStorage")
local EV = RS:WaitForChild("Events")
local SE = EV:WaitForChild("SoundEvent")
local MO = RS:WaitForChild("Modules")

SE.OnServerEvent:connect(function(PLR,soundId)
	SE:FireClient(PLR,soundId)
end)

2 comments

0

try putting SO.SoundId = tostring(id) at line 08, client side sound handler

0

ok thx

1 answer

Ok so, your sound ids are in a table. try seperating each element with a ',' instead of ';'. Using ; is just ending the line, it wont distinguish between elements if you don't use a comma. Second off, for sound ids try this instead:

SO.SoundId = "rbxassetid://" .. id;

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