yes, I forgot to add that in the code example so let me re-add that but thats not the issue.
Alright, does the soundCommand
variable include the “/” or not? if it doesn’t make this line
this
if message:sub(2, soundCommand:len()):lower() == soundCommand:lower() then
yep here is full code for more context:
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)
When I tested, I didn’t include any of the gamepass code (for obvious reasons). It gave no errors and played the sound effect I chose.
Could it be something to do with the gamepass section of code?
But how is that? The boombox clones to the player, why else isent the sound playing? Also for some reason now the ID isent going into the boombox.
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.
Source: API and save game on studio
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.
Let me know if this helps. Thanks, WE
sound is at one, and everything is on since I have leaderstats
nope, I want it to play on server so everything should work.
It works it just doesent play or anything.
Since the Boombox is parented to the Character
(a child of the workspace
) it would be server-sided.
Can you be a little more descriptive like where it doesn’t work?
- So you get the print output: “Player owns pass”
- The Boombox is properly cloned onto the player
- The Boombox has a
Handle
with aSound
child on it - When you try the command, does it put a
SoundId
onto theHandle.Sound.SoundId
?
Also, have you tried with a different sound or with multiple sounds? I tried with a handful and all of them worked fine.
Yes, most of the time the sound ID goes into the sound in handle. Can you show me the code you used?
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.
For sure, I made a file you can download that has the functional code, a boombox, etc. You can play test with a 1 person server to see the results.
BoomboxTest.rbxl (23.4 KB)
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.
I am really confused, I tried the code for me and I still can here sound, Ill try out the game download you replied as well.
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
BTW: when you are testing, is:
- 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
.
Yes there all on since I was able to hear yours, ill mess around with it a bit and ill reply if I can get it to work or not
Ah ha, Ive found the issue! Turns out I had to wait for the player added then check if they own the gamepass. I dont know why/how that fixed it but it works, thanks for all your help! @Trayeus @WEcompany @55167233gf @IEnforce_Lawz