How do random death sounds get made?

So I have seen some ways to make a random death sound, but I want to know how I can make a system that is a script so everyone can hear it like the normal Roblox oof sound, but has multiple sounds in it with a randomizer. One example is Guts & Blackpowder where if you die a randomized death sound plays.

Example text I guess:

if this player dies, play sound out of sound library, {sound1, sound2, sound3}
sound chosen after randomized math
when sound chosen play death sound when player dies

Or something like that, it doesn’t have to be the same but you get the idea?

Thanks

It’s function having math.random(1,#whatevertablesounds) and then chosen sound (which is a sound’s id inside table) gets played

you create just a table array or dicitonary (dicitonary manually need to be have a key’s name)

while array is just index (which is a number)

array table use better

(and which is a Server-side script for replicating to all clients)

1 Like

If you already have made the system, all you should need to do is make a script (NOT LOCAL) parented to StarterCharacter, if you dont have a script I made one cuz im bored lol

Script
-- Script parented to StarterCharacter
local Character = script.Parent
local Sounds = script:WaitForChild("SoundsFolder") -- or wherever you keep all the sounds
Character:WaitForChild("Humanoid").Died:Connect(function()
     local SelectedSound = Sounds[math.random(1,#Sounds)] -- gets a random sound
     SelectedSound.Parent = Character
     SelectedSound:Play()
end)

From personal experience I think it’s better to Parent the Sound to a Part of the Character like the RootPart, sounds that aren’t parented to a Part aren’t played in proximity

1 Like

I believe the simplest way to do this would be something along the lines of

local Players = game:GetService("Players")
local SoundIds = {
 -- any sound ids youd like to add to the table
}
Players.PlayerAdded:Connect(function(Player)
 Player.CharacterAdded:Connect(function(Character)
  local SelectedSoundId = "rbxassetid://"..SoundIds[math.random(1, #SoundIds)]
  Character.HumanoidRootPart:WaitForChild("Died").SoundId = SelectedSoundId
 end)
end)

You can definitely do this! The key idea is:

  1. Keep a list of possible death sounds (Sound objects you’ve set up, or IDs you insert into a folder).
  2. Detect when a player dies (Humanoid.Died).
  3. Pick a random sound from the list.
  4. Play it from the character so that everyone nearby hears it, just like the default Roblox death sound.

Here’s a simple example you can build on:

-- Script in ServerScriptService
local Players = game:GetService("Players")

-- Put your sounds in ReplicatedStorage (e.g. ReplicatedStorage.DeathSounds)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Debris = game:GetService("Debris")
local DeathSounds = ReplicatedStorage:WaitForChild("DeathSounds")

local function onCharacterAdded(character)
	local humanoid = character:WaitForChild("Humanoid")

	humanoid.Died:Connect(function()
		-- Pick a random sound from the folder
		local sounds = DeathSounds:GetChildren()
		if #sounds > 0 then
			local randomSound = sounds[math.random(1, #sounds)]:Clone()
			randomSound.Parent = character:FindFirstChild("Head") or character
			randomSound:Play()
			Debris:AddItem(randomSound, randomSound.TimeLength + 1)
		end
	end)
end

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(onCharacterAdded)
end)

Setup:

  • Create a folder in ReplicatedStorage called DeathSounds.
  • Insert Sound objects inside it with your uploaded sound IDs.

That’s it! Now when a player dies, one of those sounds will be chosen randomly and played from their character.

Hope this helps! If it solved your issue, a like would be appreciated :slightly_smiling_face:

1 Like

Thanks! It works! although the “oof” sound still plays.

Ah, yeah, that happens because Roblox has a built-in “oof” sound that plays on death, not just the Sound object in the character’s head.

You’ve got a couple ways to fix it:

  1. Use a LocalScript to stop the default sound right when the player dies:
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local humanoid = character:WaitForChild("Humanoid")
		humanoid.Died:Connect(function()
			local head = character:FindFirstChild("Head")
			if head then
				local defaultDeath = head:FindFirstChild("Death")
				if defaultDeath then
					defaultDeath:Stop()
					defaultDeath:Destroy()
				end
			end
		end)
	end)
end)
  1. Replace the default “oof” sound asset with a silent sound. Then your random death sounds will play without the oof at all.

Option 1 is usually the easiest. You can just add it alongside your existing random death sound script, and the default “oof” won’t bother you anymore.

will other players hear the oof? also where do i put the script? thanks

The way @neagup wrote his script, you would want a server script inside the ServerScriptService

So the gray script? or the local script?

Not a local script, a white one

Ok then, the one that says “script” thanks

Yes, LocalScripts are, as the name suggest, local, they only apply things on a client. Changes made through a server-script will replicate to every client (with a few exceptions)

  1. Did you use AI? :sob:
  2. Storing sounds as instances is a bad practice, because it occupies memory, store sound ids in a module instead
  3. DO NOT USE DEBRIS, do this instead:
task.delay(randomSound.TimeLength + 1, function()
    randomSound:Destroy()
end)
1 Like

No, I actually wrote it myself, but thanks for the feedback! I’ve been scripting for around 1.5 years and I’m still learning, so I really appreciate tips like this. I get what you mean about storing Sound objects. Using IDs in a module can definitely save memory. I used Debris here mainly to auto-clean cloned sounds after they play, but I’d be curious to see your approach too.

task.delay(sound.TimeLength / sound.PlaybackSpeed + 0.1, sound.Destroy, sound)
  1. you do realize debris is based on task.delay
  2. variables occupy memory too, just not as much as an instance, so rephrase ur sentence and get the facts

also

Sound.PlayOnDestroy = true (or wtv the property is)
Sound:Destroy()  --// no need to play or task.delay
1 Like

Debris is made for when you need to destroy an object within a script that may get destroyed.

For example:

  • Player has tool
  • Player activates tool which has temporary part
  • Player dies and character gets destroyed (including tool)
  • delay will not work to destroy it, debris will

I faintly remember trying this sometime before and it not working.

1 Like

you are not OP, idk why this information would matter