So i have a script that plays a sound every time a player dies. I want to make it so only that player can hear the sound instead of everyone in the server. Plz help?
There are 2 scripts that come with it:
1st:
game:GetService('Players').PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) character:WaitForChild("Humanoid").Died:connect(function() script.Parent.DeathSong:Play() wait(5.4) script.Parent.DeathSong:Stop() end) end) end)
2nd:
script.Parent.DeathSong.SoundId = script.Parent.Song.Value
You would need to play the music locally, so insert that sound into the PlayerGui.
So, have a LocalScript that controls the sounds it makes [put in the StarterGui], and either insert a sound into the PlayerGui or have a sound in the StarterGui already, both should work fine.
How to add a sound to the playergui:
game.Players.PlayerAdded:connect(function(plr) local sound = Instance.new("Sound", plr.PlayerGui) -- parents the sound in there. end)
As we know, anything that is in the StartGui will be a local item. Meaning, the sound will only play for that local player. To do this, place an audio inside of startgui.
for i,v in pairs (game.Players:GetPlayers() do wait(.5) i.PlayerGui.Sound:Play() end
local function PlaySound() [Where the sound is]:Play() end
Make sure you have this, but I don't think it is currently possible, not the way I use it for anyway, if you want to make it locally then you could put the sound in a brick, put a minimum and a maximum sound on the sound itself, and when you want to play it locate that brick where the character is. If it doesn't work, please respond back to show me what you have done