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 2 years ago

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

local okbutton = script.Parent.TextButton

function onClicked(id)
    id = script.Parent.TextBox.Text
    local music1 = Instance.new("Sound")

    music1.Parent = game.Workspace

    music1.SoundId = "http://www.roblox.com/asset/?id="..id

    wait(1)
    music1:Play()
end

script.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
2 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 — 2y
Ad
Log in to vote
0
Answered by 2 years ago

Hi there! I tried that with this LocalScript:

local okbutton = script.Parent.TextButton
local remote = script.Parent.Remote

frame = script.Parent.Parent.Frame
frame.Draggable = true
frame.Active = true
frame.Selectable = true

function onClicked(id)
    script.Parent.Remote:FireServer()
end

script.Parent.TextButton.MouseButton1Click:Connect(onClicked)

The RemoteScript (just a normal Script)

script.Parent.Remote.OnServerEvent:Connect(function(id)
    id = script.Parent:WaitForChild("TextBox")
    local music1 = Instance.new("Sound")

    music1.Name = "Music1"

    music1.Parent = game.Workspace

    music1.SoundId = "http://www.roblox.com/asset/?id="..id.Text

    wait(1)
    music1:Play()
end)

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 — 2y

Answer this question