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

How do I make a TextBox change the ID of a Sound?

Asked by 6 years ago
Edited 6 years ago

So here is my script:

game.StarterGui.RequestGUI.RequestBox.Play.MouseButton1Click:Connect(function()
local Text = game.StarterGui.RequestGUI.RequestBox.Text
game.Workspace.Sound.SoundId = "rbxassetid://"..Text
game.Workspace.Sound.Playing = true
end)

Basically, I'm trying to get it to change the SoundId of a sound in Workspace as well as make it start playing by using the ID the player puts in a textbox.

However, nothing happens when I put in the ID and hit the play button. There are 0 errors in Output and this is in a regular server script.

0
Line 4 should say: workspace.Sound:Play() SchonATL 15 — 6y
0
I did this and still nothing happens. GrandNebula 14 — 6y
0
This is using StarterGui - you need to use the GUI running in the player's PlayerGui. Sorry I have to go rn so I can't answer fully TheDeadlyPanther 2460 — 6y
0
It's good if you'll use '.Changed:connect()' for TextBox. and yes, use Sound:Play() User#17685 0 — 6y
0
Remember that connect is deprecated, use Connect now. (Example: Object.Changed:Connect() ) TheDeadlyPanther 2460 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

The problem is that you are doing this all in StarterGui. The problem is that StarterGui is simply where stuff gets cloned from (into the Player's PlayerGui, which is what you should be using instead).


Firstly, make sure your script is inside the ScreenGui you are using. This will mean that, if the code is right, it will be able to easily access the right ScreenGui.

Secondly, use your code, but localise it - by that I mean, make it all specific to ScreenGui it is in, and have it not use other ScreenGuis (like the one in StarterGui).

local Gui = script.Parent --> The ScreenGui the script is in
local Sound = game.Workspace.Sound -->> You use it more than once so you should make it a variable

Gui.RequestBox.Play.MouseButton1Click:Connect(function()
    Sound.SoundId = "rbxassetid://" ..Gui.RequestBox.Text
    Sound:Play()
end)

Hope I helped!

~TDP

Ad

Answer this question