I am trying to make it so when a user inputs a sound ID in the textbox and presses the play button
it will play the desired song. However I can't find out what's wrong. I have tried ..tonumber(input.Text)
but that does not seem to work.
local Input = script.Parent.Parent.Parent.MusicID function play() for i, v in pairs(game.Workspace:children()) do if v:IsA("Sound") then v:Destroy() end end local s = Instance.new("Sound", game.Workspace) s.SoundId = "http://www.roblox.com/asset/?id=" ..tonumber(input.Text) s.Volume = 1 s.Pitch = pitch s.Looped = true s.archivable = false repeat s:Play() wait(2.5) s:Stop() wait(.5) s:Play() until s.IsPlaying end script.Parent.MouseButton1Down:connect(play)
EDIT:
local Input = script.Parent.Parent.Parent.MusicID function play() for i, v in pairs(game.Workspace:GetChildren()) do end if v:IsA("Sound") then v:Destroy() end end local s = Instance.new("Sound", game.Workspace) s.SoundId = "http://www.roblox.com/asset/?id=" ..(Input.Text) s.Volume = 1 s.Pitch = pitch s.Looped = true s.archivable = false repeat s:Play() wait(2.5) s:Stop() wait(.5) s:Play() until s.IsPlaying script.Parent.MouseButton1Down:connect(play)
The only problem that I notice is that you have:
local s = Instance.new("Sound", game.Workspace) s.SoundId = "http://www.roblox.com/asset/?id=" ..tonumber(input.Text)
But you just need to make it like this:
local s = Instance.new("Sound", game.Workspace) s.SoundId = "http://www.roblox.com/asset/?id=" ..(Input.Text)
You don't need to make it a number, since they are two strings going together, I think it would work even with the :tonumber()
if you had 'input' capitalized like when you named the variable, the variable is 'Input'. but you put 'input' in the :tonumber()
arguments.
Nvm, I also noticed this so just replace line 4 with this:
for i, v in pairs(game.Workspace:GetChildren()) do if v:IsA("Sound") then
Whole script fixed:
local Input = script.Parent.Parent.Parent.MusicID function play() for i, v in pairs(game.Workspace:GetChildren()) do if v:IsA("Sound") then v:Destroy() end end local s = Instance.new("Sound", game.Workspace) s.SoundId = "http://www.roblox.com/asset/?id=" ..(Input.Text) s.Volume = 1 s.Pitch = pitch s.Looped = true s.archivable = false repeat s:Play() wait(2.5) s:Stop() wait(.5) s:Play() until s.IsPlaying end script.Parent.MouseButton1Down:connect(play)
tonumber()
would actually break the script. That first line, instead of doing a bunch of parent, why not just use game.Players.LocalPlayer.PlayerGui
and go from there?
With that many .Parent's it is very easy to get confused.