I tried this, but it did not work… 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)
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