|
| 09 Apr 2015 07:07 PM |
I've recently added music to a place I'm making, which is good, but now what I want to do is make it so that the music isn't playing globally throughout the entire map, and only plays within a certain area, and when a player moves out of that area, it no longer plays for that player. Is there any way to do that? Here are links to my script and relevant workspace. workspace: https://twitter.com/gorillionbucks/status/586318932228857856 script: https://twitter.com/gorillionbucks/status/586319241877520385 the first script is the one in question, the second one just makes the block invisible after a few seconds. |
|
|
| Report Abuse |
|
|
|
| 09 Apr 2015 07:09 PM |
| All you need to do is clone the audio into the player and it will only be heard by that player. This is what I do for my audio. |
|
|
| Report Abuse |
|
|
|
| 09 Apr 2015 07:10 PM |
| Also, on the side, use audio.TimePosition and audio.TimeLength to detect when audio finishes playing. |
|
|
| Report Abuse |
|
|
|
| 09 Apr 2015 07:21 PM |
| I don't have problems with the audio being heard, but I want it only to be heard in a certain area, as I want to put more than one audio track in for different locations. |
|
|
| Report Abuse |
|
|
|
| 09 Apr 2015 07:25 PM |
Add an audio to the player when they join
When in a particular area, change the audio ID to the ID you want. |
|
|
| Report Abuse |
|
|
|
| 09 Apr 2015 07:27 PM |
This can be achieved simply by a touched event to detect when a player enters an area, or even by using magnitude
http://wiki.roblox.com/index.php?title=Magnitude |
|
|
| Report Abuse |
|
|
|
| 09 Apr 2015 07:28 PM |
| How would I go about making the audio ID change in certain areas? I don't know much of roblox scripting. |
|
|
| Report Abuse |
|
|
|
| 09 Apr 2015 07:39 PM |
this is probably the worst and most simple way of doing this, but...
script in ServerScriptService that adds the audio into the player:
game.Players.PlayerAdded:connect(function(player) wait(5) local findAudio=player:FindFirstChild("MasterAudio") --checks if the audio has already been added to the player if findAudio==nil then local audio=Instance.new("Sound", player) --creates the audio audio.Name="MasterAudio" end end)
now, this is a script inside an INVISIBLE part, with CANCOLLIDE off (meaning players can walk through it). Anybody inside this part stretched around your area will hear the specific sound.
soundId=1498412 --change to the ID of the sound that will play db=false script.Parent.Touched:connect(function(hit) if db==false then --make sure this script doesn't get activated a ton of times every touch db=true --make it so this function doesn't fire again until we're done local human=hit.Parent:FindFirstChild("Humanoid") --looks for a human if human then --if the thing that touched was a human... local player=game.Players:GetPlayerFromCharacter(hit.Parent) --find the player if player then --if the player exists then local audio=player:FindFirstChild("MasterAudio") --look for the audio if audio then --if the audio exists then audio.SoundId=soundId --change the audio to the audio you want end end end wait(3) --wait 3 seconds after we're done db=false --make it so this can activate again end end)
This is not the most efficient way but it's simple to understand without scripting knowledge |
|
|
| Report Abuse |
|
|
|
| 09 Apr 2015 07:50 PM |
| I can't seem to make a part stretched out over my area, even with CANCOLLIDE off, how would you go about doing that? I also don't know how to make a part invisible, either. |
|
|
| Report Abuse |
|
|