|
| 26 Apr 2016 01:22 PM |
Hey look it's me again, that guy who's a noob at scripting but wants to make a game anyway. So I get the basic gist of how audio works, I know how to make it play perpetually from the workspace, and I also know how to put audio in blocks and make it play when you touch them.
The problem with putting it in blocks is that they fade out and can't be heard anymore when the player gets far enough away, and I don't want that to happen. What I want to do is have the different audios in the workspace, and have certain ones play when you touch certain blocks. I thought it would be easy, like I'd just have to put game.Workspace.NameofSound.Play() or something, but it doesn't seem to be that simple.
I've played several games that do this, so I know it can't be hard, but all the tutorials related to audio that I could find, are just about making one track that plays perpetually. What do I do to actually get what I'm looking for? |
|
|
| Report Abuse |
|
|
dameii
|
  |
| Joined: 22 Oct 2011 |
| Total Posts: 10435 |
|
|
| 26 Apr 2016 01:24 PM |
@noobkiller look in the property of the audio is there anything there? like a playing thing a checkmark if so then do
game.Workspace.MYAMAZINGAUDIO.Playing = true or whatever it's called. please check, cause i dont know off by heart
|
|
|
| Report Abuse |
|
|
| |
|
xLawOut
|
  |
| Joined: 28 Feb 2015 |
| Total Posts: 1782 |
|
|
| 26 Apr 2016 01:35 PM |
@damei
easier is Game.Workspace.(NAME):Play() with marked "Loop" in the audio.
☮ MERCY |
|
|
| Report Abuse |
|
|
xLawOut
|
  |
| Joined: 28 Feb 2015 |
| Total Posts: 1782 |
|
|
| 26 Apr 2016 01:36 PM |
oh god, I didn't read to end, sorry.
Why script? Just get a script that when you touch it (OnTouched) it loops (Sound.Looped = true)
☮ MERCY |
|
|
| Report Abuse |
|
|
|
| 26 Apr 2016 02:54 PM |
Well dameii, you were right about there being a checkbox for that function, it's called IsPlaying. However, trying to change it to true didn't do anything.
You know what did work, though? Look again at my original post. The reason that game.Workspace.NameofSound.play() didn't work, is because I put a "." before play when it should have been a ":"
I told ya I was a noob at this...
By the way, just to confirm: This only changes the music that the player is hearing, right? It doesn't change the music of the whole server? It's kinda hard for me to test that and find out, because I'm only one guy. |
|
|
| Report Abuse |
|
|
eRanged
|
  |
| Joined: 15 Jun 2013 |
| Total Posts: 9746 |
|
|
| 26 Apr 2016 03:02 PM |
| If it's workspace it effects everybody unless it's like some local brick or something. |
|
|
| Report Abuse |
|
|
|
| 26 Apr 2016 03:28 PM |
| Well crap. So should it affect only the player if I only put it in like, the startergui or something? Or should I make a script that inserts the sound files into they player as he enters the game, and make the scripts in the blocks play those? |
|
|
| Report Abuse |
|
|
eRanged
|
  |
| Joined: 15 Jun 2013 |
| Total Posts: 9746 |
|
|
| 26 Apr 2016 03:38 PM |
Ya but you're probably gonna need a RemoteEvent if you're planning to Make a SoundPlay from the player
|
|
|
| Report Abuse |
|
|
lululukas
|
  |
| Joined: 23 Aug 2010 |
| Total Posts: 1043 |
|
|
| 26 Apr 2016 03:39 PM |
| It plays locally if you put it in PlayerGui |
|
|
| Report Abuse |
|
|
eRanged
|
  |
| Joined: 15 Jun 2013 |
| Total Posts: 9746 |
|
|
| 26 Apr 2016 03:41 PM |
Ya but he wants different sounds to play when the player touches certain parts.
|
|
|
| Report Abuse |
|
|
lululukas
|
  |
| Joined: 23 Aug 2010 |
| Total Posts: 1043 |
|
|
| 26 Apr 2016 04:03 PM |
| from where, the brick? The torso? and is it for just you or all players? |
|
|
| Report Abuse |
|
|
eRanged
|
  |
| Joined: 15 Jun 2013 |
| Total Posts: 9746 |
|
|
| 26 Apr 2016 04:04 PM |
from the Brick.
Like
Brick1.Touched:connect(function() -- gets player not doing code cuz lazy local Sound1 = player...wherever sound is Sound1:Play() end)
Brick2.Touched:connect(function() -- gets player not doing code cuz lazy local Sound2 = player...wherever sound is Sound2:Play() end)
|
|
|
| Report Abuse |
|
|
|
| 26 Apr 2016 04:17 PM |
Okay, I've been able to put together a script that inserts all the sound files into the player's PlayerGui once he joins the game. For some reason it makes two of each sound file, but whatever. Doesn't matter.
While researching exactly how I'd go about making those sounds play, I came across this thread from back in 2014: https://forum.roblox.com/Forum/ShowPost.aspx?PostID=151253324
Does this guy's issue apply to my situation? If so, what's the ClassName that the guy forgot? |
|
|
| Report Abuse |
|
|
lululukas
|
  |
| Joined: 23 Aug 2010 |
| Total Posts: 1043 |
|
|
| 26 Apr 2016 04:17 PM |
put this script inside the brick and have the audio in replicatedstorage
script.Parent.Touched:connect(function(hit) if hit.Parent:FindFirstChild"Humanoid" then player=game.Players:GetPlayerFromCharacter(hit.Parent) c=game.ReplicatedStorage:FindFirstChild"YOURSOUNDNAME":Clone() c.Parent=player.Character.Torso c:Play() end end) |
|
|
| Report Abuse |
|
|
lululukas
|
  |
| Joined: 23 Aug 2010 |
| Total Posts: 1043 |
|
|
| 26 Apr 2016 04:18 PM |
Oops i did torso let me fix
script.Parent.Touched:connect(function(hit) if hit.Parent:FindFirstChild"Humanoid" then player=game.Players:GetPlayerFromCharacter(hit.Parent) c=game.ReplicatedStorage:FindFirstChild"YOURSOUNDNAME":Clone() c.Parent=script.Parent c:Play() end end) |
|
|
| Report Abuse |
|
|
eRanged
|
  |
| Joined: 15 Jun 2013 |
| Total Posts: 9746 |
|
|
| 26 Apr 2016 04:22 PM |
ClassName he forgot was "Sound" I think.
|
|
|
| Report Abuse |
|
|
|
| 26 Apr 2016 04:47 PM |
| Well lululukas, while the script plays the sound, It goes back to my original problem of only playing when you're near the block. Also, if you try to touch another one to change the music, the two tracks just play over each other. |
|
|
| Report Abuse |
|
|
Inigo18
|
  |
| Joined: 02 Feb 2014 |
| Total Posts: 1041 |
|
|
| 26 Apr 2016 04:49 PM |
Doing a function .Touched and then adding workspace.Audio:Play() should do the job to be honest. Like: workspace.Part.Touched:connect(function(otherPart) workspace.Audio:Play() -- I guess if you wanna make it play perpetually or not you can just change the Looped property. end)
Basically, when you put an audio in a part, it will play FROM that part, like if it was a radio. However, if you play it on workspace, it will play with the same VOLUME for everyone. Hope you understood!
|
|
|
| Report Abuse |
|
|
Inigo18
|
  |
| Joined: 02 Feb 2014 |
| Total Posts: 1041 |
|
|
| 26 Apr 2016 04:53 PM |
Ok so, I tested it and it works. It's easy, put a Sound instance in workspace, fill it with an audio ID blah blah blha. Then, create a Part, add a script INSIDE the part and put this: script.Parent.Touched:connect(function(otherPart) workspace.Sound:Play() -- I guess if you wanna make it play perpetually or not you can just change the Looped property. end) REMEMBER, the audio has to be IN workspace. If you want to make it play and stop the other tracks, well, just do: script.Parent.Touched:connect(function(otherPart) workspace.Sound:Play() -- I guess if you wanna make it play perpetually or not you can just change the Looped property. workspace.Sound2:Stop() end) Understood? Remember AUDIO's parent is WORKSPACE, and the SCRIPT's parent is the PART. Hope I helped! |
|
|
| Report Abuse |
|
|
|
| 26 Apr 2016 05:05 PM |
| Well, I can't blame you for not wanting to read through the whole thread, but we've moved past that to a more complex issue: Making the whole music system work for each player individually. I've managed to make a script that puts the sound files into the player's Playergui, but I'm still trying to figure out how to activate them from there. Lululukas here came up with a method that uses ReplicatedStorage, but it... has some issues. |
|
|
| Report Abuse |
|
|
Inigo18
|
  |
| Joined: 02 Feb 2014 |
| Total Posts: 1041 |
|
|
| 26 Apr 2016 05:08 PM |
| Ohh... Forgive me for that, could you put what you have for now so I/we can use the same names and local variables as you do?? |
|
|
| Report Abuse |
|
|
|
| 26 Apr 2016 05:18 PM |
Okay, sure! Long story short, I have the player spawn right on top of a block that does several other things, including teleport him to where the game actually begins, but what's important now is that it contains this script.
--------------------------------------------------------- Sound1 = script.Parent.Sound1 Sound2 = script.Parent.Sound2 Ready = true function onTouch(hit) local h = hit.Parent:FindFirstChild("Humanoid") if h ~= nil and Ready == true then Ready = false local plyr = game.Players:FindFirstChild(h.Parent.Name) local c = Sound1:clone() local d = Sound2:clone() c.Parent = plyr.PlayerGui d.Parent = plyr.PlayerGui wait(3) Ready = true end end
script.Parent.Touched:connect(onTouch) ----------------------------------------------------------
It won't actually stop at two sound files, but you get the gist. Sound1 becomes c, Sound2 becomes d, Sound3 will become e, and so on. The whole buisness with "Ready" is something I just now threw in so that it wouldn't make duplicates of the sound files, because that happened when I first made it up. |
|
|
| Report Abuse |
|
|
Inigo18
|
  |
| Joined: 02 Feb 2014 |
| Total Posts: 1041 |
|
|
| 26 Apr 2016 05:24 PM |
| Can't you do c:Play() and d:Play()? |
|
|
| Report Abuse |
|
|
|
| 26 Apr 2016 06:31 PM |
| Well, I mean, if it were the same script. But the idea is that I want certain sounds to start playing when a player touches certain blocks, which means it would have to work with the scripts in those blocks. I've been trying to maybe make a script that would go in the PlayerGui that reacts when blocks of certain names in the workspace are touched, but it's not really working out so far. |
|
|
| Report Abuse |
|
|