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

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

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?

4 comments

0

You can use .Touched and .TouchEnded events

0

Thanks! But how do I keep the sound file individual for each player?

0

You can put it in Player instance

0

Thanks for the help!

1 answer

✓ Accepted answer

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)

2 comments

0

So the "game.Players.PlayerAdded:connect(function(plr) end)" adds a specific audio file within the player when he joins?

0

yes, just an audio

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