Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do we play a sound when a player takes damage?

local Humanoid = game.Players.LocalPlayer.Character.Humanoid.Health

2 comments

0

Please make an attempt before asking a question,

0

i did

1 answer

✓ Accepted answer

Make sure to add an intvalue and rename it to "recentUserHP" Make sure it's parented to script1

local script1 = script.Parent -- Defining the function
local frame = script1.Frame 
local sound = Instance.new ("Sound",script1)
sound.SoundId = "http://www.roblox.com/asset/?id=386232234"
local humanoid = game.Players.LocalPlayer.Character.Humanoid 

--this function below fires whenever the humanoid's health changes.
--It also gets the health of the user at that time. (inside the parentheses)
humanoid.HealthChanged:connect(function(health) 
    if script1.recentUserHP.Value > health then 
    --this asks if the most recent HP logged is higher than the users current HP
    sound:Play()
    elseif script1.recentUserHP.Value < health then
    end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.