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

How do i make a value changeable in game?

Asked by 8 years ago
Edited 8 years ago

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

MyMusic = game.starterGui.ChangeMusic.textLabel
game.starterGui.ChangeMusic.textLabel = ("          ")

Moderator note: Please enclose code in code blocks.

2 answers

Log in to vote
3
Answered by 8 years ago

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:

local plr = game.Players.LocalPlayer -- or whatever you named it
local musicGui = plr.PlayerGui.MyMusic -- or whatever you named it
local submit = musicGui.Submit -- or whatever you named it
local input = musicGui.TextBox -- or whatever you named it
local player = musicGui.Sound

submit.MouseButton1Click:connect(function() -- Connects the MouseButton1Click event to the function
    player.SoundId = "rbxassetid://".. input.Text
end)

--[[

 That could work, although it might have some problems. The basis of this was to give you something to go off of.

--]]
0
Thank you ChrisCrazy9870 5 — 8y
0
If this solved your answer, please make sure to mark it as solved. xXLegendarySoldierXx 129 — 8y
0
Ive worked through some of your script but I cant seem to figure out where Im putting the gui and how? What is LocalPlayer? ChrisCrazy9870 5 — 8y
0
So, the LocalPlayer is the clients character. The music gui will need to go into the StarterGui, but you will not access the script like that unless you were to do, local musicGui = script.Parent xXLegendarySoldierXx 129 — 8y
0
Now, the PlayerGui is the place that holds all the Gui's and LocalScripts a player can see and use. Changing stuff in the StarterGui will literally affect nothing for the clients. So you will need to access the LocalPlayer by doing, local plr = game.Players.LocalPlayer and then access their PlayerGui by doing, plr.PlayerGui and the you can get the gui by doing, plr.PlayerGui.myMusic xXLegendarySoldierXx 129 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

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:

local Sound = game.ServerStorage.Sound
local Gui = --Access the players' GUI here, make sure to put game.Players.LocalPlayer. to access their GUI and just their GUI

Sound:Play()
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:

--Define the same variables as you did in the previous code segment

Gui.TextBox.Changed:connect(function() --Connects a function so that if any properties of the TextBox change  the value will fire.
    if Gui.TextBox.Text == "Song" then --You can put any value you want there, and the script will fire when it receives this value
        Sound:Play()
    end--Make sure you have this at the end of your if statement
end) --Make sure you have this at the end of your script

If you need anything else, feel free to reply back

Answer this question