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

How would I fix this audio script?

Asked by 10 years ago

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)

2 answers

Log in to vote
1
Answered by
ultrabug 306 Moderation Voter
10 years ago

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)
0
This solution did not work either. :( Check my edit in the question to see what I changed. IntellectualBeing 430 — 10y
0
Did you replace both line 4 and line 5? ultrabug 306 — 10y
0
Yes. IntellectualBeing 430 — 10y
0
I will repost the whole script for you. ultrabug 306 — 10y
View all comments (2 more)
0
Okay. IntellectualBeing 430 — 10y
0
Wait, when I press the play button, the button that plays the song you inputed, nothing happens? I checked the parents and everything. IntellectualBeing 430 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

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.

Answer this question