Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to convert to sound asset id?

Asked by 8 years ago

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

Log in to vote
0
Answered by 8 years ago

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
0
It changes it to the right sound id but it doesnt change the music LittleBigDeveloper 245 — 8y
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 EchoReaper 290 — 8y
0
I would recommend making multiple sounds, for each song, so you just have to stop the current one, and play the new one. TheDeadlyPanther 2460 — 8y
Ad
Log in to vote
0
Answered by
Marios2 360 Moderation Voter
8 years ago

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)
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. EchoReaper 290 — 8y
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. Marios2 360 — 8y

Answer this question