Random Death Sound Is Not Working

I have been trying to make a random death sound. I have tried using remote events, which didn’t work.
here is the script I have now

local soundids = {975173739, 1778829098, 721590903, 4932192220, 4856289549, 845287176, 168209314, 2390731795, 2440670891, 5100168644}

    local char = script.Parent
    local HRP = char.HumanoidRootPart or char:WaitForChild("HumanoidRootPart")

    game.ReplicatedStorage.DeathNoise.OnClientEvent:Connect(function()
    	HRP.Died.SoundId = "rbxassetid://"..math.random(1, #soundids)
    end)

I have been getting this error:
17:39:51.651 - Failed to load sound rbxassetid://2628538600: Unable to download sound data

Try replacing this with:

game.ReplicatedStorage.DeathNoise.OnClientEvent:Connect(function()
	HRP.Died.SoundId = "rbxassetid://"..soundids[math.random(1, #soundids)]
end)

Basically, you are attempting to concatenate a number between 1 and 10 ( the number of IDs ), to the end of the asset id link. You should instead be using that random number as an index to get the real sound ID, and concatenate that.

1 Like

Doesn’t work, still comes back with
17:39:51.651 - Failed to load sound rbxassetid://2628538600: Unable to download sound data

That is an irrelevant error. That sound ID is none of the ones above, which means your code is running just fine.

Your problem lies elsewhere in the system.

But it still plays the default death sound?

:woman_shrugging:

Theres nothing else I can do to help you since its your system, unless you provide more info.

I’ve been looking for errors that may have something to do with the script, haven’t found anything.
I can’t really give anymore information other than that the remote event fires when the character is added.

17:39:51.651 - Failed to load sound rbxassetid://2628538600: Unable to download sound data

Fyi, none of the sounds in your table have the id 2628538600.

Have you tried playing the sound? This error may have nothing to do with the above code.

Furthermore, that sound id has actually been removed for copyright.

KeysOfFate already told me that

If you wanted to, you could just do this locally without remote events, and place the code in StarterCharacterScripts for ease of use.

It seems a little unnecessary to use remotes in this case, since the client can just use SCS to load code on new character creation.

Please reply to the rest of my comment.

No, I’ll try that now.
It might be from a previous attempt

1 Like

That ID is irrelevant to the current script. Note this:

  1. Client changed the sound ID, this should be the server’s functionality and not client.
  2. The ID is not in the table.
  3. The script may or may not be outside the working perimeters of LocalScript.

It wont let me play it, when I put in the SoundId and error shows up in output:

[18:23:50.141 - Sound "rbxassetid://2628538600" failed to load in "Workspace.Sound.SoundId": Request Failed](rbxopenprop://0%2e6729263/SoundId)

I forgot to mention that I had tried doing it on the server, but would come back saying:
Attempted to index nil with 'Character'

Playtest this. It’s the code I wrote above, altered to run locally when a new character is created by using StarterCharacterScripts. I basically just removed the remotes, and it works just fine/does the same thing.

demo.rbxl (20.7 KB)

1 Like

It seems to work in baseplate, but wont work with the game. I’ll try and look for something that could be interfering.

EDIT: The sound plays, then it stops a second after

The script’s location in which the code resides should be in StarterCharacterScripts. If it isn’t, my simplified method won’t work. This doesn’t necessarily mean your other code should be in SCS.

As for your edit, did this occur on the baseplate file I sent?

The problem didn’t happen on the baseplate file.

You could just put the script from the baseplate file in the same location within your game file. I cant really help you much further, at least not tonight. Sorry.