|
| 22 Jun 2013 09:24 PM |
| Alright, so I have an RPG game and I want to add music to it. Like, how do I do this? I have tried to put the music in the Workspace and then put a Script in the music say "Script.Parent:play()" It did not work in online, only in test. So I tried this "game.Workspace.Music:play()". The sound is called music. Anyways, same thing happened there. Is ther ea way to put music in a game? Like some Rpg games. |
|
|
| Report Abuse |
|
|
Zkiller11
|
  |
| Joined: 25 Aug 2009 |
| Total Posts: 2914 |
|
|
| 22 Jun 2013 09:29 PM |
| Do you have the correct SoundID set? And if so, is the code inside a LocalScript? |
|
|
| Report Abuse |
|
|
|
| 22 Jun 2013 09:35 PM |
| Yes, and Yes. But it only works in Test Mode. as in "Tools-Test-Play Solo". |
|
|
| Report Abuse |
|
|
|
| 22 Jun 2013 09:43 PM |
-- Add a checking statement.
wait(1) if script.Parent.IsPlaying == false then script.Parent:play() else then repeat() end |
|
|
| Report Abuse |
|
|
|
| 22 Jun 2013 09:44 PM |
| -- As you may know, I am new to RBX.Lua...I don't know if it should be repeat() or repeat, although it might be repeat |
|
|
| Report Abuse |
|
|
|
| 22 Jun 2013 09:51 PM |
local debounce = false function Play(newPlayer) if debounce == false then debounce = true script.Parent.MUSICNAMEHERE:Play().Parent = newPlayer repeat wait() until music.IsPlaying = false end end end
game.Players.ChildAdded:connect(Play)
Must be in a model
game> Workspace> model> Music(Sound) script
Model must contain the script and Music in one model |
|
|
| Report Abuse |
|
|
|
| 22 Jun 2013 09:52 PM |
I might have added an extra end or may be missing one. Please check
|
|
|
| Report Abuse |
|
|
|
| 22 Jun 2013 09:54 PM |
| @zk, Local scripts are mainly for Guis and self running scripts. Nothing to do with sound playing. |
|
|
| Report Abuse |
|
|
tigerr666
|
  |
| Joined: 13 Aug 2009 |
| Total Posts: 1665 |
|
|
| 22 Jun 2013 09:59 PM |
@Epic, I recently learned coroutines for lua, and repeat has no "()" after it. :) Example: coroutine.resume(coroutine.create(function() repeat game.Workspace.bla:destroy() until game.Workspace.bla == nil end)) |
|
|
| Report Abuse |
|
|
Zkiller11
|
  |
| Joined: 25 Aug 2009 |
| Total Posts: 2914 |
|
|
| 22 Jun 2013 10:01 PM |
@Cooldude:
Yea, I know that. It's just usually if a script doesn't work online but on test it's because it needs to be a LocalScript (in my own experience). |
|
|
| Report Abuse |
|
|
|
| 22 Jun 2013 10:02 PM |
coroutine.create(function(remove) roblox.Forum.Scripting_Helpers.How_to_add_sound_to_a_game?.AbovePost:Destroy end)
print(coroutine.Status(remove))
|
|
|
| Report Abuse |
|
|
|
| 22 Jun 2013 10:03 PM |
| Lel mines was for the coroutine learner not you xD |
|
|
| Report Abuse |
|
|