I’m making this command based music changer. I’m having problems with one of the commands. I want it to get the asset id “rbxassetid://00000000” from the end of "/changeMusic " and put it in a variable. Short explanation:
A player says “/changeMusic rbxassetid://00000000” in the chat.
We want to get the “rbxassetid://00000000” off of that message, and store it in a variable.
Code (This is in a local script.):
local function musicFunction()
local music = Instance.new("Sound")
music.Parent = game.Workspace
music.Name = "Cynacol's Music"
music.SoundId = "rbxassetid://342274063"
music.Looped = true
music.Volume = 2
local player = game.Players.Cynacol
if string.sub(string.lower(msg), 1, 10) == "/stopMusic" then
if string.sub(string.lower(msg), 1, 10) == "/playMusic" then
if string.sub(string.lower(msg, 1, 13) == "/changeMusic " then
-- In here is where we want to obtain the "rbxassetid://00000000" off of the player, and store it in the music's SoundId.
The function string.split() splits a string into parts based on the specified delimiter (2nd string value argument passed to the function), in this case I’ve split the bit you don’t want from the bit you do want. The returned value is an array of strings, we want the 2nd element of that array so “” is used to index the 2nd item of that array. Which in turn is the part of the string you want.