Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I keep an audio file active only within a specific area?

Asked by 8 years ago

For instance, I want a lobby sound file active only when I'm in the lobby, and when I get teleported to another location (outside the lobby), I want the script to change the volume of that audio file to 0.

Does anyone have any clue how to make this work?

0
You can use .Touched and .TouchEnded events Mokiros 135 — 8y
0
Thanks! But how do I keep the sound file individual for each player? Hyperclux 65 — 8y
0
You can put it in Player instance Mokiros 135 — 8y
0
Thanks for the help! Hyperclux 65 — 8y

1 answer

Log in to vote
1
Answered by
NotSoNorm 777 Moderation Voter
8 years ago

Well for this, there are multiple ways,

  • One way is to make the sound play within a brick that's within the room.

  • Another way is you could insert a sound into the playergui and play depending on whatever brick they're touching.

Now the first one is pretty self explanatory but I should explain the second one.

Now like @Mokiros said, You could use touch events, For this we should put the sound in the player gui, so...

game.Players.PlayerAdded:connect(function(plr)
    local audio = Instance.new("Sound") 
    audio.Parent = game.Workspace[plr.Name]
end)

Now that we've set up where the audio is, We can now change it with an touched event,

game.Players.PlayerAdded:connect(function(plr)
    local audio = Instance.new("Sound") 
    audio.Parent = game.Workspace[plr.Name]
    audio.Name = "LocalAudio"
    game.Workspace.'Partname here'.Touched:connect(function()
        game.Players[plr.Name].PlayerGui.LocalAudio.SoundId = "Sound id here"
        game.Players[plr.Name].PlayerGui.LocalAudio:Play()
    end)
end)
0
So the "game.Players.PlayerAdded:connect(function(plr) end)" adds a specific audio file within the player when he joins? Hyperclux 65 — 8y
0
yes, just an audio NotSoNorm 777 — 8y
Ad

Answer this question