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

TextButton doesn't work in a sound player I made. How could this be fixed?

Asked by 4 years ago

So basically, this sound player makes itself with a script. When it's done, it makes a textbox that you can put the sound asset id into, and an "Enter" button that will copy it into an audio object then it should play. The problem is that the button doesn't work. From videos I've seen, it seems to work just fine and gets me confused.

Thanks in advance. :)

MusicGUI = Instance.new("ScreenGui", game.StarterGui)
MainFrame = Instance.new("Frame", MusicGUI)
SoundIdBox = Instance.new("TextBox", MainFrame)
TitleLabel = Instance.new("TextLabel", MainFrame)
EnterButton = Instance.new("TextButton", MainFrame)

MusicGUI.Enabled = true
MusicGUI.Name = "MusicGUI"

MainFrame.Visible = true
MainFrame.Name = "MainFrame"
MainFrame.Position = UDim2.new(0.7,0,0.23,0)
MainFrame.Size = UDim2.new(0,290,0,275)
MainFrame.Active = true
MainFrame.BackgroundTransparency = 0.65
MainFrame.BackgroundColor3 = Color3.new(0,0,0)
MainFrame.BorderSizePixel = 3
MainFrame.BorderColor3 = Color3.new(255,255,255)

SoundIdBox.Name = "SoundIdBox"
SoundIdBox.MultiLine = false
SoundIdBox.Position = UDim2.new(0.125,0,0.25,0)
SoundIdBox.Size = UDim2.new(0.75,0,0.15,0)
SoundIdBox.TextScaled = true
SoundIdBox.BackgroundColor3 = Color3.new(255,255,255)
SoundIdBox.BackgroundTransparency = 0
SoundIdBox.Visible = true
SoundIdBox.Font = "Arial"
SoundIdBox.BorderSizePixel = 3
SoundIdBox.BorderColor3 = Color3.new(65,65,65)
SoundIdBox.TextColor3 = Color3.new(0,0,0)
SoundIdBox.Text = ""

TitleLabel.BackgroundTransparency = 1
TitleLabel.Name = "TitleLabel"
TitleLabel.Text = "Sound Player"
TitleLabel.Font = "Code"
TitleLabel.TextColor3 = Color3.new(0,0,0)
TitleLabel.Position = UDim2.new(0.15,0,0,0)
TitleLabel.Size = UDim2.new(0.75,0,0.175,0)
TitleLabel.TextScaled = true
TitleLabel.TextColor3 = Color3.new(255,255,255)
TitleLabel.Active = true

EnterButton.Name = "EnterButton"
EnterButton.Text = "Enter"
EnterButton.BackgroundTransparency = 0
EnterButton.BackgroundColor3 = Color3.new(5,5,5)
EnterButton.BorderSizePixel = 2
EnterButton.BorderColor3 = Color3.new(255,255,255)
EnterButton.Position = UDim2.new(0.78,0,0.43,0)
EnterButton.Size = UDim2.new(0.1,0,0.075,0)
EnterButton.Font = "ArialBold"
EnterButton.TextScaled = true
EnterButton.Active = true

function onClick()
        print("Clicked")
        local audio = Instance.new("Sound", game.Workspace)
        audio.SoundId = "\"rbxassetid://"..SoundIdBox.Text.."\""
        audio:Play()
    end
EnterButton.MouseButton1Click:connect(function(onClick)
end)

:)

1 answer

Log in to vote
0
Answered by 4 years ago

Follow this steps to make it work perfectly:

  1. Create a screenGui inside of the StarterGui folder
  2. Create a local script inside of that GUI
  3. Put this improved code of that one inside of that local script:
MusicGUI = script.Parent
MainFrame = Instance.new("Frame", MusicGUI)
local SoundIdBox = Instance.new("TextBox", MainFrame)
TitleLabel = Instance.new("TextLabel", MainFrame)
EnterButton = Instance.new("TextButton", MainFrame)

MusicGUI.Enabled = true
MusicGUI.Name = "MusicGUI"

MainFrame.Visible = true
MainFrame.Name = "MainFrame"
MainFrame.Position = UDim2.new(0.7,0,0.23,0)
MainFrame.Size = UDim2.new(0,290,0,275)
MainFrame.Active = true
MainFrame.BackgroundTransparency = 0.65
MainFrame.BackgroundColor3 = Color3.new(0,0,0)
MainFrame.BorderSizePixel = 3
MainFrame.BorderColor3 = Color3.new(255,255,255)

SoundIdBox.Name = "SoundIdBox"
SoundIdBox.MultiLine = false
SoundIdBox.Position = UDim2.new(0.125,0,0.25,0)
SoundIdBox.Size = UDim2.new(0.75,0,0.15,0)
SoundIdBox.TextScaled = true
SoundIdBox.BackgroundColor3 = Color3.new(255,255,255)
SoundIdBox.BackgroundTransparency = 0
SoundIdBox.Visible = true
SoundIdBox.Font = "Arial"
SoundIdBox.BorderSizePixel = 3
SoundIdBox.BorderColor3 = Color3.new(65,65,65)
SoundIdBox.TextColor3 = Color3.new(0,0,0)
SoundIdBox.Text = ""

TitleLabel.BackgroundTransparency = 1
TitleLabel.Name = "TitleLabel"
TitleLabel.Text = "Sound Player"
TitleLabel.Font = "Code"
TitleLabel.TextColor3 = Color3.new(0,0,0)
TitleLabel.Position = UDim2.new(0.15,0,0,0)
TitleLabel.Size = UDim2.new(0.75,0,0.175,0)
TitleLabel.TextScaled = true
TitleLabel.TextColor3 = Color3.new(255,255,255)
TitleLabel.Active = true

EnterButton.Name = "EnterButton"
EnterButton.Text = "Enter"
EnterButton.BackgroundTransparency = 0
EnterButton.BackgroundColor3 = Color3.new(5,5,5)
EnterButton.BorderSizePixel = 2
EnterButton.BorderColor3 = Color3.new(255,255,255)
EnterButton.Position = UDim2.new(0.78,0,0.43,0)
EnterButton.Size = UDim2.new(0.1,0,0.075,0)
EnterButton.Font = "ArialBold"
EnterButton.TextScaled = true
EnterButton.Active = true

function onClick()

    local list = workspace:GetChildren()

for i = 1, #list do

if list[i].ClassName == "Sound" then

    list[i]:Destroy()

end 

end

       local texto = script.Parent.MainFrame.SoundIdBox.Text
print(texto)
       local audio = Instance.new("Sound", game.Workspace)
     audio.SoundId = "rbxassetid://"..SoundIdBox.Text..""
      audio:Play()
    end
script.Parent.MainFrame.EnterButton.MouseButton1Click:Connect(onClick)

There you go :D

0
thanks :) SilverCreeper58 23 — 4y
Ad

Answer this question