I’ve made a vending machine SENT, and in the process of polishing it, I came up with the idea to play sounds when the player uses it. However, I’m having issues getting the sound to play individually if multiple SENTs are spawned in. The problem I’m having, is that the system works by the client sending a concommand to the server half of the SENT. Because of that, I cannot access variables or use Entity:EmitSound.
Here is my attempt to explain it:
SENT spawns, this runs on shared:
The player walks up and uses the machine. An interface opens up asking them what they would like to purchase. This runs on the client when the menu opens:
function ENT:Initialize() ID = self:GetNetworkedVar("VendingID") end
The player then selects what he wants and confirms the selection:
concommand.Add( "vend_interface", function( args ) // Super secret GUI Button.DoClick = function () RunConsoleCommand( "vend_buyitem", arg1, arg2, selection, ID) Popup:SetVisible( false ) Popup:Close() end end
We move to the server half, the SENT receives the concommand:
concommand.Add( "vend_buyitem", function( ply, cmd, args ) // Checks if you can afford // Removes money if you have it Entity( arg ):EmitSound("path",100,100) // Player notification end )
Strangely, this works if there is only 1 machine spawned. But if more than one is spawned, the sound is emitted from the most recent one.
Any help is appreciated, thanks.