biny7884Join Date: 2012-03-21 Post Count: 22 |
I have no idea how to make sound local not global.
Any help?
|
|
|
Put the sound instance within the player of your choice. It can even be inside a descendant of the player. |
|
biny7884Join Date: 2012-03-21 Post Count: 22 |
So, how would I do this exactly. I am kind of a beginner here but I know quite a bit of code
|
|
biny7884Join Date: 2012-03-21 Post Count: 22 |
Would I put the sounds in replicatedstorage and then clone them into someone when they join?
|
|
ImVortexeJoin Date: 2013-01-26 Post Count: 1149 |
game.Players.PlayerAdded:connect(function(player)
Instance.new("Sound", player.PlayerGui) |
|
|
Theres a function is SoundService that plays a sound only for the client.
--Put this code in a script that should be the parent of the sound.
game:GetService("SoundService"):PlayLocalSound(script.Parent) |
|
|
There's a function in SoundService* |
|
biny7884Join Date: 2012-03-21 Post Count: 22 |
Thanks for the reply but I am actually dying this is impossible...
I am making a gamepass button and trying to play differ music when pressed but the problem is that it plays the mmusic for the whole client. I see that this was helpful if there was a different type of scenario but this one is just, GRRRRR..
Script inside of a button inside of a screengui in startergui
--------------------------------------
local Button = script.Parent
local Guisound = workspace.MusicFolder.Guimusic.Script
local Normalsound = workspace.MusicFolder.Adventure.Script
Box = script.Parent.Parent.Box
Frame = script.Parent.Parent.Frame
PCWARS = script.Parent.Parent.Frame.PCWARS
GAMES = script.Parent.Parent.Frame.GAMES
DEVELOP = script.Parent.Parent.Frame.ImageLabel
----------------------Code----------------------------
function onClick()
if Box.Visible == false then
DEVELOP.Visible = true
GAMES.Visible = true
PCWARS.Visible = true
Box.Visible = true
Frame.Transparency = 0
Normalsound.Parent.Playing = false
Guisound.Parent.Playing = true
Button.Text = "Gamepasses{ALPHA SALE}"
elseif Box.Visible == true then
DEVELOP.Visible = false
GAMES.Visible = false
PCWARS.Visible = false
Box.Visible = false
Frame.Transparency = 1
Guisound.Parent.Playing = true
Normalsound.Parent.Playing = false
Button.Text = "Gamepasses{ALPHA SALE}"
end
end
Button.MouseButton1Click:connect(onClick)
-----------------------El' fine-------------------------
Any help will be much appreciated on this occasion..
|
|
nullfeelsJoin Date: 2017-03-31 Post Count: 1215 |
Okay so... If you want to play a sound globally don't do anything special to it, just put it in the workspace or a folder in the workspace, etc.
If you want to play a 3D positional sound you put the sound file INSIDE of a part or union, and it will play the sound from that location.
If you want to play a sound only for one player then use the PlayLocalSound function of the SoundService. game.SoundService:PlayLocalSound(sound) |
|
nullfeelsJoin Date: 2017-03-31 Post Count: 1215 |
Also, just an additional tip, but code like:
if something.Visible == true then
is unnecessary and redundant. Instead use just:
if something.Visible then
It is the same thing, but cleaner, more professional even... and if you want to check if, for example, something is not visible...
if not something.Visible then
is the preferred way of doing that. Nothing wrong with your code, but just wanted to mention that. |
|
nullfeelsJoin Date: 2017-03-31 Post Count: 1215 |
One more tip... In your on click event handler function you check if the box is not visible and if it is visible. This is also very redundant. Instead just check if the box is visible or else. i.e.:
if box.Visible then
do something
else
do something else
end
That is all :P And again I'm not trying to nitpick, but small changed like this will make your code much cleaner and easier to maintain in the end. |
|
|
Insert the sound in the object you want, for example if its a wall make the Sound Parent The wall
Then in the properties of the sound you can edit the range from where you can hear it.
Hope this helps |
|
biny7884Join Date: 2012-03-21 Post Count: 22 |
Ok this is actually getting on my nerves now can someone write me the code plz because this is my code and it seems fine(I haven't changed to what the other guy said :P)
game:GetService("SoundService")
local Button = script.Parent
local Adventure = script.Parent.parent.MusicFolder.Adventure
local Guimusic = script.Parent.Parent.MusicFolder.Guimusic
local Box = script.Parent.Parent.Box
Frame = script.Parent.Parent.Frame
PCWARS = script.Parent.Parent.Frame.PCWARS
GAMES = script.Parent.Parent.Frame.GAMES
DEVELOP = script.Parent.Parent.Frame.ImageLabel
function onClick()
if Box.Visible == false then
DEVELOP.Visible = true
GAMES.Visible = true
PCWARS.Visible = true
Box.Visible = true
Guimusic.Volume = 0.5
Guimusic:PlayLocalSound()
Adventure.Volume = 0
# #Fr################## 0
Button.Text = "Gamepasses{ALPHA SALE}"
elseif Box.Visible == true then
DEVELOP.Visible = false
GAMES.Visible = false
PCWARS.Visible = false
Box.Visible = false
Adventure.Volume = 0.5
Adventure:PlayLocalSound()
Guimusic.Volume = 0
################## = 1
Button.Text = "Gamepasses{ALPHA SALE}"
end
end
Button.MouseButton1Click:connect(onClick)
|
|
nullfeelsJoin Date: 2017-03-31 Post Count: 1215 |
Your code has a lot of issues to be honest, but here... I cannot guarantee this to work, it's just your code rewritten with errors corrected.
local soundService = game.SoundService
local button = script.Parent
local adventure = script.Parent.Parent.MusicFolder.Adventure
local guiMusic = script.Parent.Parent.MusicFolder.GuiMusic
local box = script.Parent.Parent.Box
local frame = script.Parent.Parent.Frame
local pcwars = script.Parent.Parent.Frame.PCWARS
local games = script.Parent.Parent.Frame.GAMES
local develop = script.Parent.Parent.Frame.ImageLabel
button.MouseButton1Click:connect(function()
if (not box.Visible) then
develop.Visible = true
games.Visible = true
pcwars.Visible = true
box.Visible = true
soundService:PlayLocalSound(guiMusic)
adventure.Volume = 0
else
develop.Visible = false
games.Visible = false
pcwars.Visible = false
box.Visible = false
adventure.Volume = 0.5
soundService:PlayLocalSound(adventure)
guiMusic.Volume = 0
--whatever the censored thing is = 1
button.Text = "Gamepasses{ALPHA SALE}"
end
end) |
|
biny7884Join Date: 2012-03-21 Post Count: 22 |
The only error I see related to the code is...
17:50:05.214 - SoundService is not a valid member of DataModel
17:50:05.215 - Stack Begin
17:50:05.216 - Script 'Players.Player1.PlayerGui.ScreenGui.OpenClose.Script', Line 1
17:50:05.216 - Stack End
|
|
biny7884Join Date: 2012-03-21 Post Count: 22 |
And how do you know all this stuff?
i would love to know
|
|
nullfeelsJoin Date: 2017-03-31 Post Count: 1215 |
Hmm that's strange. Try replacing local soundService = game.SoundService with local soundService = game:GetService("SoundService")
And I've just been a programmer for many years. It just come with time and practice. Just keep working at it, you'll get there. |
|
biny7884Join Date: 2012-03-21 Post Count: 22 |
Null, you have fixed it the only problem is how do I turn off the music when I have started playing it with a piece of code....
|
|
biny7884Join Date: 2012-03-21 Post Count: 22 |
By "A piece of code" I mean when I have wrote soundService:PlayLocalSound(guiMusic)
|
|
nullfeelsJoin Date: 2017-03-31 Post Count: 1215 |
The Sound class has a Stop function. i.e. adventure:Stop() Should work. |
|
nullfeelsJoin Date: 2017-03-31 Post Count: 1215 |
Also, this is your new best friend. ########################################################## |
|
nullfeelsJoin Date: 2017-03-31 Post Count: 1215 |
Nope! Wasn't him :P google roblox api should be the first link. |
|
biny7884Join Date: 2012-03-21 Post Count: 22 |
Null, got discord if so just send there.
+If I had 300 robux it would go to you for your help xD.
Sadly I don't have 300 robux :P
|
|
nullfeelsJoin Date: 2017-03-31 Post Count: 1215 |
Nah, I don't have discord ATM. And don't worry about it, glad to help. :) |
|
biny7884Join Date: 2012-03-21 Post Count: 22 |
xD The stop isn't working xD
|
|