Sound playing inside character

Hello all! I am currently making a penguin game and for some reason when I click a button (GUI) It won’t play the sounds (Penguin noises)

-- emp long
p = game.Players.LocalPlayer.Character
local Sound = game.Workspace.Sounds.Emperor.Long

function OnClicked() 
    Sound = Instance.new'Sound'
	Sound.Parent = p
	Sound.Volume = 4
	Sound.Looped = false
	Sound.PlayOnRemove = false
	Sound.SoundId = "http://www.roblox.com/asset/?id=9568194621"
	Sound:Play()
end 

I used to use this script that worked:

-- emp short
Sound = game.StarterPlayer.Sounds.Emperor.Short

function OnClicked() 
	Sound:Play()
end 

script.Parent.MouseButton1Down:connect(OnClicked)

But It played in the game and not in the character, I also wanted everyone to here the noises.

1 Like

Your sound needs to be in Workspace if you want the server to hear it… and although it is here

you then parent it back to the player here

Parent it to the workspace instead.

Here is the new version:

-- emp long
local Sound = game.Workspace.Sounds.Emperor.Long

function OnClicked() 
    Sound = Instance.new'Sound'
	Sound.Parent = Sound
	Sound.Volume = 4
	Sound.Looped = false
	Sound.PlayOnRemove = false
	Sound.SoundId = "http://www.roblox.com/asset/?id=9568194621"
	Sound:Play()
end 

No sound. Im trying to make the sound inside the character so when you get close to the character you hear the noise, but further away you don’t.

I was confused as to what you wanted… but read this thread and its solution, it will help you achieve what you want:

infos

    1. Use the “SoundService” storage to put global sounds in it.
    1. Sounds are replicated from where the sound is placed.
      If the sound isn’t in a physical object (part, mesh) then it will be global (everyone will hear it).
      If the sound is in a physical object, then it will played from this part (so you can hear it only if you’re close to it, depending of the “RollofMaxDistance” and “RollofMinDistance” sound properties settings).
    1. If you want that everyone can hear the sound, it need to be played in server side using a script and not a local script.

Here is more infos about sounds :slight_smile:
https://developer.roblox.com/en-us/api-reference/class/Sound
https://developer.roblox.com/en-us/api-reference/property/Sound/RollOffMode

Solution

So, here is the solution.

  • Put your Sound inside the “SoundService”
  • Add a “LocalScript” in your Gui button
  • Add a “Remote Event” in the replicated storage, Rename it “SoundReplication”
  • Add a “Script” inside the “ServerScriptService”
  • Don’t forget to change the “RollOffMin and Max distance” of your sound (5 for min and 35 for max should be fine)

Local Script code:

local Player = game.Players.LocalPlayer
local Character = Player.Character

local Sound = game.SoundService:WaitForChild("Long" ,30)
local Root = Character:WaitForChild("HumanoidRootPart" ,30)
local Event = game.ReplicatedStorage:WaitForChild("SoundReplication" ,30)

local Cooldown = false

if Sound ~= nil and Root ~= nil and Event ~= nil then
	script.Parent.MouseButton1Click:Connect(function()	
		if Cooldown == false then
			Cooldown = true
			Event:FireServer(Sound, Root)
			wait(0.5) --cooldown to avoid spam click
			Cooldown = false
		end
	end)
end

Script code:

local Event = game.ReplicatedStorage:WaitForChild("SoundReplication" ,30)

if Event ~= nil then
	Event.OnServerEvent:Connect(function(Player, Sound, Root)
		coroutine.resume(coroutine.create(function()
        -- Coroutine = as there is a wait time in the script, it is in case if multiple sounds are played on differents players at same time, allow the script to be played multiple times at once.
			local Clone = Sound:Clone()
			Clone.Parent = Root
			Clone:Play()
			wait(0.5)--SoundTime
			Clone:Destroy()
		end))
	end)
end
2 Likes

You are parenting the sound to the character model instead of a part making the sound not play, the first script should look something like this:

-- emp long
p = game.Players.LocalPlayer.Character
local Sound = game.Workspace.Sounds.Emperor.Long

function OnClicked() 
    Sound = Instance.new'Sound'
	Sound.Parent = p.HumanoidRootPart
	Sound.Volume = 4
	Sound.Looped = false
	Sound.PlayOnRemove = false
	Sound.SoundId = "http://www.roblox.com/asset/?id=9568194621"
	Sound:Play()
end 
1 Like

Ignore my other post your a life saver I swear to god, I put the script in the wrong game lol.