Help with scripting random death sounds

Hello everyone, I am an absolute beginner at scripting, so I apologize for my very basic question. I am attempting to add multiple custom death sounds to my game so that a random sound ID will play for each death. However, I’m only able to add to get one working at a time. I basically want 25 death sounds in the game, and when the player dies, it pulls one at random to play. How would I do this? Can I simply add the sound IDs to my current script or do I need to add something extra? This is my script so far:

local Players = game:GetService("Players")
local Player = Players.LocalPlayer

function ChangeDeathSound()
	local Character = Player.Character or Player.CharacterAdded:Wait()
	local DiedSound = Character.PrimaryPart:FindFirstChild("Died")
	if DiedSound then
		DiedSound.SoundId = "rbxassetid://5646824941"
	end
end

I appreciate any feedback, and thank you for being patient with us coding noobs :slight_smile:

1 Like

I would recommend doing something like this

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local DeathSounds = {die sound1, die sound2, die sound3}

function DieSound(die)
    local Humanoid = die:FindFirstChild("Humanoid")
        if Humanoid.Health == 0 then
        SoundId = DeathSounds[math.random(1, 3)]

essentially in the “DeathSounds” table you would put the different sound IDs and when the player dies, you would get a random one to play.

I hope this works and I wish you good luck!

1 Like

Thank you so much! What was confusing me most was trying to add some sort of library that the script could pull the sound IDs from. This is way more simple than I expected. I really appreciate it :slight_smile:

1 Like