Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to convert to sound asset id?

So ive made a script when you put a word into a textbox it puts it into the sound id. But how do i make it so i only put a "Sound Id" then it puts the "http://www.roblox.com/asset?id=" behind it. For example I put 1010101 in and then it turns it to http://www.roblox.com/asset?id=1010101

Frame = script.Parent.Parent
Button = script.Parent
Text1 = Frame:WaitForChild("ID")
Music = game.StarterGui.ScreenGui.Script

Part = Music:WaitForChild("Sound")

a = Frame:WaitForChild("ID")

script.Parent.MouseButton1Click:connect(function()
    Part.SoundId = a.Text
end)

2 answers

The way to do it is this:

Part.SoundId = "http://www.roblox.com/asset?id=" .. a.Text
Part:Play()

You can do this with strings, E.G:

local name = "TREE"
local age = 5

print("My name is " ..name.. " and I am " ..age.. " years old!")

EDIT:

To change songs, you will need to :Stop() the music, then play it again. I prefer the cleaner way below (having multiple songs).

loccal songs = songsFolder:GetChildren()
local currentSong = nil

function changeSong(songNum)
	songs[currentSong]:Stop()
	songs(songNum):Play()
	currentSong = songNum
end

while true do
	wait(40)
	changeSong(math.random(1,#songs))
end

3 comments

0

It changes it to the right sound id but it doesnt change the music

0

Just for reference, combining strings and variables like that is a process called "concatenation" if you ever come across that word at some point

0

I would recommend making multiple sounds, for each song, so you just have to stop the current one, and play the new one.

To use a sound from the Roblox library, you use the actually correct way to refer to the sound's id:

http://www.roblox.com/asset/?id=whatevertheidis

To then make the Sound instance play the newly found sound, you would have to stop it and replay it:

workspace.Part.Sound.SoundId = http://www.roblox.com/asset/?id=firstid
workspace.Part.Sound:Play()
wait(5)
workspace.Part.Sound.SoundId = http://www.roblox.com/asset/?id=secondid --The sound doesn't change when i input the new Id
wait(2)
workspace.Part.Sound:Stop()
workspace.Part.Sound:Play() -- It changes once i replay it here

EDIT - The script again doesn't work. Why would that be? Well, StarterGui contents get all sent to each player's PlayerGui. You want to affect that sound which the player gets. So instead of

game.StarterGui.ScreenGui.Script

You use

script.Parent.Parent.Parent.Parent.Parent.Script

Thus here is the fixed script:

Frame = script.Parent.Parent
Button = script.Parent -- This variable is never used, you can delete this
Text1 = Frame:WaitForChild("ID") -- This line is obsolete due to the "a" variable below, you should better delete it
Music = script.Parent.Parent.Parent.Parent.Parent.Script

Part = Music:WaitForChild("Sound")

a = Frame:WaitForChild("ID")

script.Parent.MouseButton1Click:connect(function()
    Part.SoundId = "http://roblox.com/asset/?id=" .. a.Text
    Part:Stop()
    --Part:Play() -- This line is optional, uncomment if you want the sound to play itself at your looper script afterwards.
end)

2 comments

0

You don't need to have the sound in your inventory to be able to play it. Also, he posted a separate question about the sound not changing when the ID was changed (https://scriptinghelpers.org/questions/22819/sound-id-doesnt-work), so you should tranfer your answer to there.

0

@above That is considered, and by most if not all points of view it is a duplicate question. This is the original question so we answer here.

This discussion is preserved as it was. New answers, comments, and votes are closed.