game.Players.ChildAdded:connect(function(child)
local function PlaySound(id)
local sound = Instance.new("Sound",child:findFirstChild("PlayerGui"))
sound.SoundId = "http://www.roblox.com/asset/?id= "..tostring(id)
sound.Volume = 1
sound:Play()
repeat sound:Play() wait(2.5) sound:Stop() wait(2.5) sound:Play() until sound.IsPlaying
TextBox = child:findFirstChild("PlayerGui"):findFirstChild("ScreenGui").Music.Enter
TextButton = TextBox:findFirstChild("Play")
end
TextButton.MouseButton1Click:connect(function()
PlaySound(tonumber(TextBox.Text))
end)
end)
--I have tried numerous times everythings in the right spot in the GUIS and frames but it keeps erroing with that same annoying error. Any help?
How come the error keeps saying "attempt to index a nil value"?[UNSOLVED]
1 answer
Style
Tab your code correctly. You should probably also avoid putting 4 statements on a single line...
:findFirstChild is deprecated. Use :FindFirstChild instead.
FindFirstChild
:FindFirstChild can return nil if the object does not exist.
If you are sure the object will exist, there is no reason to use :FindFirstChild:
TextBox = child.PlayerGui.ScreenGui.Music.Enter
Clearly one of these objects does not exist. In that case, you should use :WaitForChild if you are sure they will eventually exist:
TextBox = child:WaitForChild("PlayerGui"):WaitForChild("ScreenGui").Music.Enter
Style
You should use local variables if those variables are only used in one function. It will save yourself headaches later.
3 comments
Doesnt work.
Why not? What's it do instead?
Dude no need to negative vote me. It just doesnt implement a sound in my playergui. Whenever i press the play button. And theres no errors i did what you said.
This discussion is preserved as it was. New answers, comments, and votes are closed.

7 comments
What line specifically is giving you this error?
8-9
@EgoMoose
does child have a variable / is child defined?
yes @doctortardiswho child is from the event chiladded.
When you have an error, paste it exactly as a part of the question.
Are you using FilteringEnabled?