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)
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
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)