How would I make characters spawn with an additional sound in their HumanoidRootPart?

I’ve noticed players spawn with several sounds in their HumanoidRootPart, I simply want to add another that I can use later, but I can’t figure out how. I’ve scoured the forums and nothing seemed to help.

This is simple to implement. You need only detect when each player in the server (re)spawns, then copy a Sound instance into their character’s “HumanoidRootPart”.

Below is a Script in ServerScriptService, with the sound named “Sound” as a child:

--!strict
local Players = game:GetService("Players")


local Sound = script.Sound



local function onCharacterAdded(character: Model & any)
	local humanoidRootPart = character.HumanoidRootPart
	local soundCopy        = Sound:Clone()

	soundCopy.Parent = humanoidRootPart
end

local function onPlayerAdded(player: Player)
	local character = player.Character

	if character then
		onCharacterAdded(character)
	end

	player.CharacterAdded:Connect(onCharacterAdded)
end



for _, player in Players:GetPlayers() do
	onPlayerAdded(player)
end

Players.PlayerAdded:Connect(onPlayerAdded)

Be sure to use Instance:WaitForChild when accessing the copied sound as Roblox does not guarantee script execution order (the sound could be copied too late)

1 Like

Thanks much!
I’ll be sure to analyze the code so I can understand it

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.