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

A script that play a music in a game?

Asked by 3 years ago

So I made a GUI and put this script in it.

01local okbutton = script.Parent.TextButton
02 
03function onClicked(id)
04    id = script.Parent.TextBox.Text
05    local music1 = Instance.new("Sound")
06 
07    music1.Parent = game.Workspace
08 
09    music1.SoundId = "http://www.roblox.com/asset/?id="..id
10 
11    wait(1)
12    music1:Play()
13end
14 
15script.Parent.TextButton.MouseButton1Click:Connect(onClicked)

Well, it's not working. Can somebody help me fix this?

2 answers

Log in to vote
0
Answered by
Rukreep 15
3 years ago

Make sure it's a LocalScript. You also need to use RemoteEvents for such. RemoteEvents send commands from the player to the server. For example, you click the button and it sends an imput to the server saying to do such. You can find more here: https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events

0
I tried that with another method, but it's still not working.I have described everything in more detail below. I would be very grateful if you would read it. Mimas18Hun 0 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

Hi there! I tried that with this LocalScript:

01local okbutton = script.Parent.TextButton
02local remote = script.Parent.Remote
03 
04frame = script.Parent.Parent.Frame
05frame.Draggable = true
06frame.Active = true
07frame.Selectable = true
08 
09function onClicked(id)
10    script.Parent.Remote:FireServer()
11end
12 
13script.Parent.TextButton.MouseButton1Click:Connect(onClicked)

The RemoteScript (just a normal Script)

01script.Parent.Remote.OnServerEvent:Connect(function(id)
02    id = script.Parent:WaitForChild("TextBox")
03    local music1 = Instance.new("Sound")
04 
05    music1.Name = "Music1"
06 
07    music1.Parent = game.Workspace
08 
09    music1.SoundId = "http://www.roblox.com/asset/?id="..id.Text
10 
11    wait(1)
12    music1:Play()
13end)

And I get this error every time: Failed to load sound http://www.roblox.com/asset/?id=: Unable to download sound data (x2) - Studio

0
It appears that your 'id.Text' variable is not a valid sound id. appxritixn 2235 — 3y

Answer this question