--I seem to have trouble getting the ID in the textbox. It keeps saying attempt to index a nil value and I don't even know what that means. Any help?
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
local TextBox = child:findFirstChild("PlayerGui"):findFirstChild("ScreenGui").Frame.TextBox
local TextButton = TextBox:findFirstChild("Play")
TextButton.MouseButton1Click:connect(function()
PlaySound(tonumber(TextBox.Text))
end)
end
end)
✓ ANSWER ACCEPTED
Can you guys help me with this?
1 answer
✓ Accepted answer
You have numerous issues that will not allow the code to run. nil is a use of saying there is no value... it comes from the latin word nihil meaning nothing.. here is the definition:
http://www.thefreedictionary.com/nil
Now, your issue relies on the playing to happen within the function itself... this should now work.
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").Frame.TextBox
TextButton = TextBox:findFirstChild("Play")
end
TextButton.MouseButton1Click:connect(function()
PlaySound(tonumber(TextBox.Text))
end)
end)
--[[ This should now work, since the attempt to play the music is not done within the function itself, but in the outside code, if it does not... send me a pm on Roblox (User: Taryo) ]]
~Taryo
This discussion is preserved as it was. New answers, comments, and votes are closed.
