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

Can you guys help me with this?

Asked by 8 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.
--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)

1 answer

Log in to vote
0
Answered by
Scarious 243 Moderation Voter
8 years ago

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

Ad

Answer this question