I want to add a gui feature that allows players to change the value in the box and play there own music. How do I make the script find this value from the gui and change the music for that player. This is what I have correct my mistakes so far
1 | MyMusic = game.starterGui.ChangeMusic.textLabel |
2 | game.starterGui.ChangeMusic.textLabel = ( " " ) |
Moderator note: Please enclose code in code blocks.
Umm that is not going to work because you're accessing the the StarterGui, when you should be accessing the PlayerGui. When a game starts up, everything in the StarterGui gets cloned into the PlayerGui. You can access that by saying, player.PlayerGui.
Also, use a TextBox so users can put in their own link and have a submit button to play the music. Like so:
01 | local plr = game.Players.LocalPlayer -- or whatever you named it |
02 | local musicGui = plr.PlayerGui.MyMusic -- or whatever you named it |
03 | local submit = musicGui.Submit -- or whatever you named it |
04 | local input = musicGui.TextBox -- or whatever you named it |
05 | local player = musicGui.Sound |
06 |
07 | submit.MouseButton 1 Click:connect( function () -- Connects the MouseButton1Click event to the function |
08 | player.SoundId = "rbxassetid://" .. input.Text |
09 | end ) |
10 |
11 | --[[ |
12 |
13 | That could work, although it might have some problems. The basis of this was to give you something to go off of. |
14 |
15 | --]] |
This isn't working because you are only changing this value to the local player, this doesn't affect the whole server. To do this you could always do something like so:
1 | local Sound = game.ServerStorage.Sound |
2 | local Gui = --Access the players' GUI here, make sure to put game.Players.LocalPlayer. to access their GUI and just their GUI |
3 |
4 | Sound:Play() |
5 | Gui.TextLabel = "This song" -- Or whatever you want to insert. |
If you want it so that they insert their own value, do something like so:
1 | --Define the same variables as you did in the previous code segment |
2 |
3 | Gui.TextBox.Changed:connect( function () --Connects a function so that if any properties of the TextBox change the value will fire. |
4 | if Gui.TextBox.Text = = "Song" then --You can put any value you want there, and the script will fire when it receives this value |
5 | Sound:Play() |
6 | end --Make sure you have this at the end of your if statement |
7 | end ) --Make sure you have this at the end of your script |
If you need anything else, feel free to reply back