Problem Playing Sounds Using Chat Commands

I’ve this script I was trying to mess around with in Studio, where the ID I was using on line three was replaced with “ID” before posting here. It’s a server script in ServerScriptStorage:

local Sound = Instance.new("Sound")
Sound.Parent = game.SoundService
Sound.SoundId = "rbxassetid://ID"

local PitchShifter = Instance.new("PitchShiftSoundEffect")
PitchShifter.Parent = game.SoundService

local function ApplyEffect(effectType, value)
	if effectType == "shift" then
		PitchShifter.Octave = value
	end
end

game.Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msg)

		if msg == '/play' then
			game.SoundService.Sound:Play()
		end

		if string.lower(string.sub(msg, 1, 6)) == "/shift" then
			local success, failure = pcall(ApplyEffect, "shift", tonumber(string.sub(msg, 7, string.len(msg))))

			if failure then
				print("The function call failed. Did you enter in an appropriate value?")
			end
		end
	end)
end)

I’m fully aware that the pcall is probably unnecessary and that the programming style is sloppy but bear with me here. Whenever I attempt to get the sound to play, the sound doesn’t and nothing is shown in the console… I’m left to believe it’s not a syntax error but a logic one that I can’t pinpoint. Not to mention half the time I hit “play” and load into Studio, the chat vanishes on me and I’m unable to bring it up unless I hit stop and play again.

What am I doing wrong here?

Seems like it’s the single quotations that you used instead of the normal ones on line 15. It should look like:

if msg == “/play” then
game.SoundService.Sound:Play()
end

Single quotations or not. It works the same.

Oh rip. Don’t deal much with strings.

Hopefully you meant ServerScriptService here and not ServerStorage, since you merged the two names together. Code doesn’t run in ServerStorage.

As for the sound issue, the server cannot play sounds in SoundService. Move your sound elsewhere such as the Workspace and try again. The server only replicates playback, however it’s not like a client machine with an audio output so it’s a bit restricted in what it can do.

I had it placed in ServerSciptService initially. My apologies for the type-o.

I did as you have suggested and it worked. Thank you!