1 | lplayer.Chatted:Connect( function (msg) |
2 | if string.sub(msg, 1 , 7 ) = = (prefix.. "music " ) then |
3 |
4 | end |
5 | end ) |
so I get up to this point then I don't know what to do where it gets the ID from you saying :music [ID} then it plays. Anybody know?
Use gsub to replace your prexfix and "music " with "", that will leave you with just the ID. From there you can create a sound in workspace with the ID and play it
example script:
01 | game.Players.PlayerAdded:connect( function (Player) |
02 | Player.Chatted:connect( function (Message) |
03 | if string.sub(Message, 1 , 7 ) = = ":music " then |
04 | local ID = string.gsub(Message, ":music " , "" ) |
05 | if workspace:FindFirstChild( "Sound" ) then |
06 | workspace.Sound:Remove() |
07 | end |
08 | local Sound = Instance.new( "Sound" , workspace) |
09 | Sound.SoundId = "rbxassetid://" ..ID |
10 | Sound.Looped = true |
11 | Sound:Play() |
12 |
13 | end |
14 | end ) |
15 | end ) |
Since you want to do this from a local script, you won't be able to create a new sound instance for everyone, so no one else will be able to hear the music. So, what you need to do is use remote events:
your local script:
1 | local RE = game.ReplicatedStorage:WaitForChild( "MusicEvent" ) |
2 | local localPlayer = game.Players.LocalPlayer |
3 |
4 | localPlayer.Chatted:connect( function (Message) |
5 | if string.sub(Message, 1 , 7 ) = = ":music " then |
6 | local ID = string.gsub(Message, ":music " , "" ) |
7 | RE:FireServer(ID) |
8 | end |
9 | end ) |
Server script inside of server script service:
01 | local RE = Instance.new( "RemoteEvent" ) |
02 | RE.Parent = game.ReplicatedStorage |
03 | RE.Name = "MusicEvent" |
04 |
05 | RE.OnServerEvent:Connect( function (player, musicID) |
06 | if workspace:FindFirstChild( "Sound" ) then |
07 | local Sound = workspace.Sound |
08 | Sound:Stop() |
09 | Sound.SoundId = "rbxassetid://" ..musicID |
10 | Sound.Looped = true |
11 | Sound:Play() |
12 | else |
13 | local Sound = Instance.new( "Sound" ) |
14 | Sound.SoundId = "rbxassetid://" ..musicID |
15 | Sound.Looped = true |
16 | Sound.Parent = workspace |
17 | Sound:Play() |
18 | end |
19 | end ) |
If this answers your question then mark it as the accepted answer. I can also clear up any further questions you might have about this.
I made it so it's possible for you to add other commands, if "music" is not where you're going to stop at
01 | local Players = game:GetService( "Players" ); |
02 | local admins = { "tantec" } ; |
03 | local sound = Instance.new( "Sound" ); |
04 | sound.Parent = workspace; |
05 | local prefix = ":" ; |
06 | local commands = { |
07 | music = function (id) |
08 | sound.SoundId = tonumber (id); |
09 | sound:Play(); |
10 | end ; |
11 | } ; |
12 |
13 | for i,v in pairs (Players:GetPlayers()) do |
14 | local check = false ; |
15 | for a,b in pairs (admins) do |