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

How do i make a script that plays a sound when my player has been damaged?

Asked by 6 years ago
Edited 6 years ago

Hello, I would like to know how to make a script that plays a sound when the player has been damaged by anything, like in the script you have a roblox id and you enter the of number of the search number of the sound. Something like when damaged play sound? Thanks for helping me.

1 answer

Log in to vote
0
Answered by 6 years ago

This is a help forum, not a request site. However I would still try using a script along the lines of:

-- StarterCharacterScript
hum = script.Parent.Humanoid
last = hum.Health
mysound = Instance.new("Sound", script.Parent)
mysound.SoundId = 1337 -- Sound ID
hum.Changed:Connect(function()
    if hum.Health ~= last and hum.Health < last then
        print("i've been damaged!")
        mysound:Play()
    end
last = hum.Health
end

This script checks to see if the health is less than it was before. If it works let me know please!

0
You should use the HealthChanged event instead of the Changed event mattscy 3725 — 6y
Ad

Answer this question