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

[UNSOLVED] How do I make music system server sided?

Asked by 3 years ago
Edited 3 years ago

So I'm trying to create a server script that plays audio to the whole server, I've tried this on a local script, just testing to see if at least one player can hear the audio. It worked perfectly on the local script, I tried pasting the same script into a server script and it didn't play anything, all it did was insert the text rbxassetid:// into sound id.

Here's the code:

-- \\ CONTROL SCRIPT

local textbox = script.Parent.TextBox
local textbutton = script.Parent.TextButton

textbutton.MouseButton1Click:Connect(function()
    tostring(textbox.Text)
    game.Workspace.Sound.SoundId = "rbxassetid://"..textbox.Text
end)

Can someone help me out? Thanks! :)

2 answers

Log in to vote
0
Answered by 3 years ago

The reason why your sound id is not changing is that the textbox text does not actually change on the server when you change it locally. In other words, the server cannot read the changes that the client makes to the textbox, so therefore it would just be empty on the server.

To fix this, you could either use a RemoteEvent or a RemoteFunction. I would recommend using a RemoteEvent because RemoteFunctions can cause infinite yielding (depending on how you handle it), so using a RemoteEvent is the safer route.

Have a local script send in the textbox's text to the server when you click the button (fire a RemoteEvent), and then in the server script that catches the event, take the information that the client sent you and apply it how you did it in your code.

0
Thanks for the help but can you help me make this event? I've never really touched remote functions of events before.. xMas_Ier 1 — 3y
0
Forgot to mention, I do know how to fire the remote event but I dont know how to send the textbox text to the event. xMas_Ier 1 — 3y
0
Sorry for the late reply, but basically, when you fire the event you send it in like this: RemoteEvent:FireServer(text) Brandon1881 721 — 3y
0
And on the server, you catch it like this: RemoteEvent.OnServerEvent:Connect(function(text) --do code end) Brandon1881 721 — 3y
View all comments (4 more)
0
Take a look at this page if you need more help with that: https://developer.roblox.com/en-us/api-reference/class/RemoteEvent Brandon1881 721 — 3y
0
I've done all of that but I get the error "attempt to concatenate string with Instance" what does this mean and what do I do? xMas_Ier 1 — 3y
0
Oh sorry, on the server it would be caught like this: "RemoteEvent.OnServerEvent:Connect(function(player, text) --do code end)" because the first parameter is always the player who fired the event. Brandon1881 721 — 3y
0
Really sorry for annoying you with this but now it says this: Failed to load sound rbxassetid://: Unable to download sound data (x2) and it isn't showing the text from the textbox. xMas_Ier 1 — 3y
Ad
Log in to vote
-1
Answered by 3 years ago

1st Add a Sound in the workspace and add a script and name it Music then put this script into the
Music local Sound1 = 0
local Sound2 = 0
local Sound3 = 0 local Sound4 = 0 local Sound5 = 0 local Sound6 = 0 local Sound7 = 0 local Sound8 = 0 local Sound9 = 0 local Sound10 = 0 local Sound11 = 0 local Sound12 = 0 local Sound13 = 0 local Music = game.Workspace.Sound wait(5) while true do Music.SoundId = "rbxassetid://"..Sound1 Music:Play() wait(170) Music.SoundId = "rbxassetid://"..Sound2 Music:Play() wait(110) Music.SoundId = "rbxassetid://"..Sound3 Music:Play() wait(177) Music.SoundId = "rbxassetid://"..Sound4 Music:Play() wait(1) Music.SoundId = "rbxassetid://"..Sound5 Music:Play() wait(120) Music.SoundId = "rbxassetid://"..Sound6 Music:Play() wait(50) Music.SoundId = "rbxassetid://"..Sound7 Music:Play() wait(49) Music.SoundId = "rbxassetid://"..Sound8 Music:Play() wait(160) Music.SoundId = "rbxassetid://"..Sound9 Music:Play() wait(160) Music.SoundId = "rbxassetid://"..Sound10 Music:Play() wait(160) Music.SoundId = "rbxassetid://"..Sound11 Music:Play() wait(160) Music.SoundId = "rbxassetid://"..Sound12 Music:Play() wait(160) Music.SoundId = "rbxassetid://"..Sound13 Music:Play() wait(60)

end

You can change the 0 to the music ids you want and the wait() for how long the sound is.

0
I think you've been mistaken! I wanted it so that when the button gets clicked the id from the textbox will go to the sound id. xMas_Ier 1 — 3y
0
then yes i have been mistaken Mel_pro1 5 — 3y

Answer this question