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?
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
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)
Keep a list of possible death sounds (Sound objects you’ve set up, or IDs you insert into a folder).
Detect when a player dies (Humanoid.Died).
Pick a random sound from the list.
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
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:
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)
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.
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)
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.