Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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.

5 comments

0

Line 4 should say: workspace.Sound:Play()

0

I did this and still nothing happens.

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

0

It's good if you'll use '.Changed:connect()' for TextBox. and yes, use Sound:Play()

0

Remember that connect is deprecated, use Connect now. (Example: Object.Changed:Connect() )

1 answer

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.