Playing custom sounds [Gamemode]

So I’ve tried adding a sound whenever the client presses the USE button (Which is E). But It doesn’t play the sound, all it gives me in console is this,



Failed to load sound "sound\allahu.wav", file probably missing from disk/repository


There is no other lua errors, just this part. I’ve tried fixing it by myself for a while now but I failed, so I came here for some help, what was I doing wrong?
The Path for the sound file, \Steam\SteamApps\common\GarrysMod\garrysmod\gamemodes\creative\content\sound\allahu.wav .
And the Path for the lua file, \Steam\SteamApps\common\GarrysMod\garrysmod\gamemodes\creative\gamemode\init.lua .
Here is the code that I’m talking about. Its located in init.lua .



AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")

resource.AddFile("sound/allahu.wav")

AddCSLuaFile("cl_powers.lua")
include("sv_powers.lua")

include("shared.lua")

local ply=FindMetaTable("Player")

function GM:KeyPress(ply,key)
if key==IN_USE and ply:Alive() then
		if expt==0 then
		expt=1
		local exp=ents.Create("env_explosion")
		exp:Spawn()
		exp:SetKeyValue("iMagnitude",200)
		exp:EmitSound( "sound/allahu.wav" )
		timer.Simple(.5,function()
		exp:SetPos(ply:GetPos())
		exp:Fire("Explode",0,0)
		expt=0
		end)
	else 
		sound.Play("weapons/slam/buttonclick.wav",Vector(ply:GetPos()))
	end
	end


Thanks.

When you are playing a sound it looks in the sound folder instantly so you don’t need any folder paths unless it is not in the sound folder. If you where to have the sound in sound/explosive/allahu.wav then you would use the path explosive/allahu.wav.

Try



exp:EmitSound("allahu.wav")


Thank you for the quick reply and explanation, it worked!

[editline]19th March 2016[/editline]

Another question, How do I force the client side to download the sound file?

No Problem, resource.AddFile() Is what you use to force the user to download the file.




if ( SERVER ) then
    resource.AddFile( "sound/allahu.wav" )
end



Thank you again.

Look here for more info on EmitSound: https://wiki.garrysmod.com/page/Global/EmitSound