Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to have your character make a sound if he's injured?

Asked by 10 years ago

Like if you got shot, it'll play a sound. Like "Braaa" or "OOOH." And it randomly selects a sound each time you are you are injured. Something like this.

            local NewHealth = Humanoid.Health + (Humanoid.Health/Humanoid.MaxHealth) + 1
            if NewHealth = Humanoid.Health and Humanoid.Health = -1 < 
                then
                sound1:play()
            end

And another sound will play depending on how much damage you take. Like in older games (Preferably DOOM, Quake, and Serious Sam) where when you take damage, your guy will make a sound.

if NewHealth = Humanoid.Health and Humanoid.Health = - 1< -- you take greater than 1 damage, it'll ---play
      then
      sound1:play() 
end
0
This is all in a health GUI script, by the way. TheRings0fSaturn 28 — 10y

2 answers

Log in to vote
0
Answered by
Gamenew09 180
10 years ago

To get when a player gets hurt we need to connect the humanoid Changed event and then check in the function if the property changed was Health. After we check if the property changed was the health we then check if the last health we got from the humanoid is below the current health after that we would play the sound.

The Lua conversion:

-- This goes at the top of the script.
local lh = 0
local ply = game.Players.LocalPlayer

-- This goes in the character event in the health script
local humanoid = ply.Character.Humanoid
lh = ply.Character.Humanoid.Health
humanoid.Changed:connect(function(prop)
    if prop == "Health" then
        if lh > humanoid.Health then -- This checks if health is below the last health from the humanoid
            print("Play sound")
        end
        lh = ply.Character.Humanoid.Health
    end
end)

I check if this works and it does, so if it doesn't you can ask me to help you more.

0
So, how does this make your character play a sound, exactly? TheRings0fSaturn 28 — 10y
0
You would have to replace print("Play sound") to playing it. Gamenew09 180 — 10y
0
do you have to keep the green part? GlxkTerrence 5 — 6y
Ad
Log in to vote
0
Answered by 10 years ago

i think next to play type in () the id of the audio idk

Answer this question