How do I create a death sound?

I’m currently working on a rocket fighting game and I was wondering how I would go about implementing a kill sound for when you eliminate another player.

5 Likes

You can set the death sound, which is found in the character’s HumanoidRootPart.

The path looks something like this: Character.HumanoidRootPart.Died, which is the sound instance.
You can set this from a server script when the character is loaded.

Happy New Year :partying_face:

6 Likes

Bind the sound playing function to an event which fires when the player dies.

Here’s some info on Humanoid.Died, and some info of how to play music.

4 Likes

hi, im confused u want when u die or when u kill? if u die then (a script in ServerScriptService)


game.Players.PlayerAddded:Connect(function(plr)
      plr.CharacterAdded:Connnect(fuction(char)
              local hum = char:WaitForChild(char)
                     hum.Died:Connect(function()
                     char.HumanoidRootPart.Died:Play()
              end)
       end)
end)


5 Likes

I want a noise to play when you kill another player.

1 Like

in your weapon script, idk how u detect if the hit is a player but if it have touch:

local hum = hit.Parent:FindFirstChild('Humanoid')
if hum then
spawn(function()
if hum.Health <= 0 then
local plr = player -- This is if u use the rocket script with RemoteEvents(first argument need to be player)
if plr.Character then
plr.Character.Humanoid.Died:Play()

                     end
                 end)
            end
      end 
3 Likes

Play to every player on the server, or just the player who killed the other player?

2 Likes

The player who killed the other player.

3 Likes

Several ways exist to achieve this :

To detect and play a sound upon dying, or killing you would :

First of all you would need to know how to bind a function locally for a player upon the player dying. (If your game uses tools to kill then you can implement a similar code to play a sound for the person who killed too) .

You could compare the Humanoid’s state (inefficient)

Or just bind Humanoid.Died directly to a function (Through a local script in Starter Character Scripts) .

   Humanoid.Died:Connect(function()

that would only run once the event fires , telling us the Humanoid has died,
but a somewhat redundant check could still be added here,

 if Humanoid:GetState() == Enum.HumanoidStateType.Dead then
 --// Variables
 local Character = script.Parent 
 local player = Character.Parent

 local Humanoid = Character:WaitForChild("Humanoid")
 local sound = script.Parent:WaitForChild("DeathSound")
-- Sound must be parented to StarterCharacterScripts
 sound.Parent = script.Parent:WaitForChild("HumanoidRootPart")

  --// Function
   Humanoid.Died:Connect(function()--only when he dies
     sound:Play()
	 wait(1)
  end)   
As for playing a sound for the killer, you would :

Parent the Sound to StarterCharacterScripts and if you use tools to kill players in your game then use the mouse.hit to detect a player like

local tag = Instance.new('ObjectValue')
tag.Parent = hit.Parent.Humanoid

and change the tag’s value to the player or his name , in which case you would just loop through players , get the player whose name matches that value ( name of the " killer" ) , and play the sound for that player too, or you could see if a player’s mouse’s hit.Parent.Humanoid is dead , if so then just simply play the sound through a local script.

The default death sounds automatically play upon player death, so I did not assume you wanted me to manually play them for no apparent reason.

10 Likes

Thank you, that helps a lot! :slight_smile:

4 Likes

Can this be achieved and created in way of how Grand Theft Auto 5 has it?

1 Like

did some research and yeah you can, pretty much any sound at all, you any connect any function to that event to do anything you want (fire another event, fire the Client, give cash etc . , or like in your case manipulate the camera as well) .