Hi, so I am relatively new to scripting and am attempting to set up a system for players to let their songs be played in the game in a certain area. It is controlled using a GUI and includes local scripts. So I have used remote events. The only issue is the song will only change on the player’s side and not anyone else’s. This is what the scripts look like.
Local Script: local music = game:GetService("ReplicatedStorage").Music local IDN = script.Parent.Parent.TextBox.Text
Also, whenever you provide code, PLEASE preformat it. It makes it much easier to read. You can do this by highlighting your code, then click the </> button.
You’re indexing the text from the TextBox before it’s actually modified by the user – this variable isn’t dynamic meaning it does not auto-update.
-- localscript
local music = game:GetService("ReplicatedStorage").Music
script.Parent.MouseButton1Click:Connect(function()
music:FireServer(script.Parent.Parent.TextBox.Text) -- direct reference to the input
end)
music.OnClientEvent:Connect(function(IDN)
local Sound = workspace.BeachSpeaker.Sound
Sound.SoundId = "rbxassetid://" .. IDN
Sound:Play()
end)
You also may want to add validation on both the server and client to make sure the ID isn’t blank.
Well. He has a button that has to be clicked. So I assume the player enters ID and then presses button. So text has to be updated. Oh, wait I see what you mean. @ryantubelive you have to get the text in the mouse click function since you need it to be up to date.
I saw you modified your post but I’ll explain it a little more in depth for clarification.
On run-time the IDN variable is being set to an empty string (that’s the default value of the textbox.) When the left mouse button is clicked you’re firing the remote and passing IDN as a variable, which is still empty because the reference is never updated to the new value of the textbox.