Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

A script that play a music in a game?

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

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

1 comment

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.

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

1 comment

0

It appears that your 'id.Text' variable is not a valid sound id.

This discussion is preserved as it was. New answers, comments, and votes are closed.