Im making a boombox gamepass but for some reason the audio wont play when you say in chat /music ID. I check the sound in studio and the id is in it but it just wont play. Thanks!
Code Snippet:
player.CharacterAdded:Connect(function(character)
local boombox = game.ServerStorage.Boombox:Clone()
boombox.Parent = character
player.Chatted:Connect(function(message)
if message:sub(1, soundCommand:len()):lower() == soundCommand:lower() then
local soundID = message:sub(soundCommand:len() + 1)
boombox.Handle.Sound.SoundId = "http://www.roblox.com/asset/?id="..soundID
boombox.Handle.Sound:Play()
end
end)
end)
player.CharacterAdded:Connect(function(character)
local boombox = game.ServerStorage.Boombox:Clone()
boombox.Parent = character
player.Chatted:Connect(function(message)
if message:sub(1, soundCommand:len()):lower() == soundCommand:lower() then
local soundID = message:sub(soundCommand:len() + 1)
boombox.Handle.Sound.SoundId = "http://www.roblox.com/asset/?id="..soundID
boombox.Handle.Sound:Play()
end
end) -- this was missing
end)
A end) tag was missing for the player.Chatted connection.
Lemme know if more errors still occur?
local MarketplaceService = game:GetService("MarketplaceService")
local soundCommand = "/music "
local gamepassId = 15075233
game.Players.PlayerAdded:Connect(function(player)
if MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamepassId) then
print("Player owns pass.")
player.CharacterAdded:Connect(function(character)
local boombox = game.ServerStorage.Boombox:Clone()
boombox.Parent = character
player.Chatted:Connect(function(message)
if message:sub(1, soundCommand:len()):lower() == soundCommand:lower() then
local soundID = message:sub(soundCommand:len() + 1)
boombox.Handle.Sound.SoundId = "http://www.roblox.com/asset/?id="..soundID
boombox.Handle.Sound:Play()
end
end)
end)
else
print("Player does not own pass.")
end
end)
I’ve had no issue with the code whatsoever, the only problem I can see is that maybe the Sound.Volume is too low? I tested and my “Boombox” was a floating part so I set the .Volume to 10 for testing (even after the Boombox is parented under my Character) and it still worked.
edit:
Also, do you get any errors whatsoever?
second edit:
I would possibly consider allowing access to Studio API services as well (this includes DataStores). I’m not sure if that would make a difference.
Also try the code without the if statement checking for the gamepass and see if it works that way too.
Try to add more print() to let us see that the script works.
local MarketplaceService = game:GetService("MarketplaceService")
local soundCommand = "/music "
local gamepassId = 15075233
game.Players.PlayerAdded:Connect(function(player)
print("Player added.")
if MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamepassId) then
print("Player owns pass.")
player.CharacterAdded:Connect(function(character)
print("Player's character added.")
local boombox = game.ServerStorage.Boombox:Clone()
boombox.Parent = character
player.Chatted:Connect(function(message)
print("Player chatted.")
if message:sub(1, soundCommand:len()):lower() == soundCommand:lower() then
print("The player has just said the command.")
local soundID = message:sub(soundCommand:len() + 1)
boombox.Handle.Sound.SoundId = "http://www.roblox.com/asset/?id="..soundID
boombox.Handle.Sound:Play()
end
end)
end)
else
print("Player does not own pass.")
end
end)
Im pretty sure if you want to play sounds in the client, you need a local script.
repeat wait() until game:IsLoaded() -- So nothing crashes, doesn't work in ServerScripts, and not even needed for those.
local player = game:GetService("Players").LocalPlayer
local boombox = function()
local boombox = game.ServerStorage.Boombox:Clone()
boombox.Parent = character
player.Chatted:Connect(function(message)
if message:sub(1, soundCommand:len()):lower() == soundCommand:lower() then
local soundID = message:sub(soundCommand:len() + 1)
boombox.Handle.Sound.SoundId = "http://www.roblox.com/asset/?id="..soundID
boombox.Handle.Sound:Play()
end
end)
end)
boombox()
Make this script a local script, and put it in PlayerScripts.
Put the boombox model in ReplicatedStorage, for LocalScripts can’t access ServerStorage.
I have tried @55167233gf prints and it all seems to working, I added a print(“playing”) after the audio is played and and runs threw but theres still no audio being played.
As for the code, it is included with the file, but I will also put it here for anyone who doesn’t want to download the entire project.
-- The SoundId I used: 323899165
--local MarketplaceService = game:GetService("MarketplaceService")
local soundCommand = "/music "
--local gamepassId = 15075233
game.Players.PlayerAdded:Connect(function(player)
--if MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamepassId) then
print("Player owns pass.")
player.CharacterAdded:Connect(function(character)
local boombox = game.ServerStorage:WaitForChild("Boombox"):Clone()
boombox.Parent = character
player.Chatted:Connect(function(message)
if message:sub(1, soundCommand:len()):lower() == soundCommand:lower() then
local soundID = message:sub(soundCommand:len() + 1)
boombox.Handle.Sound.SoundId = "http://www.roblox.com/asset/?id="..soundID
boombox.Handle.Sound:Play()
end
end)
end)
--[[else
print("Player does not own pass.")
end--]]
end)
Of course, I have the Gamepass & MarketplaceService disabled because it wouldn’t work for me otherwise. Your’s should work since you own the Gamepass.
Also, the Sound I used is quite loud so be aware of that.
okay so, I have tried you game and it works, I really don’t know why it doesn’t work in my games though, maybe it has something do to the boombox I’m using? idk lol
Your computer volume not muted (yes I know it is a dumb question just making sure)
Your ROBLOX Studio sound under the volume mixer is not at 0 (Right click Sound Icon on your task bar – bottom right – and then click “Open Volume Mixer” and look for studio while the application is open).
When you’re testing, the view window where the game is highlighted.
The mute button (under Studio: Test tab->Mute) isn’t selected.
Also, just seen your post as I was typing this:
I’m not sure, how was your Boombox setup? Was it an Accessory with a Handle part like mine?
Also, you are free to the Boombox in the project if it works for you. I didn’t make the mesh, I just made the Accessory.