Custom Death Sounds

I tried this, but it did not work… :frowning: This is a local script in StarterCharacterScripts

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local DeathSounds = game.Workspace.DeathsFolder:GetChildren()
local randomsound = math.random(1, #DeathSounds)
		

local humanoid = player:FindFirstChild("Humanoid")
humanoid.Died:Connect (function()
	randomsound:Play()
end)


1 Like

you don’t need the space between connect and function

You need to get the player character to get the humanoid.

local Character = player.Character or player.CharacterAdded:Wait()

local Humanoid = Character:FindFirstChild(“Humanoid”)

Put it in StarterPlayerScripts also maybe check this out

The humanoid is the part of the character and not the player. You also need to actually play the sound and not a number. Maybe take a look at this. To accomplish what you are trying to do, you could put

local Players = game:GetService("Players")
local Humanoid = Players.LocalPlayer.Character:FindFirstChild("Humanoid") -- FindFirstChild simply until instance given is loaded
local DeathSounds = game.Workspace.DeathsFolder:GetChildren() -- This is correct, you are creating a table of all the instances/sounds in the directory game.Workspace.DeathsFolder
local randomSound = DeathSounds[math.random(1, #DeathSounds)] -- This is what you need to change, instead of only creating a random number, you are using that number to play that table value

humanoid.Died:Connect(function() -- Remove the space :)
	randomSound:Play() -- This is now playing the actual sound instead of attempting to play a number (because that makes no sense XD)
end)

Make sure to put this inside a localscript within the StarterPlayerScripts and not the StarterCharacterScripts. Hope this helps! Any questions you can just ask :slight_smile:

2 Likes

I’ve put it in StarterPlayerScripts and it does not work, but it does work in StarterCharacterScripts