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

How do we play a sound when a player takes damage? [closed]

Asked by 5 years ago
Edited 5 years ago

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

0
Please make an attempt before asking a question, Brandon1881 721 — 5y
0
i did Xx0966xX 41 — 5y

Closed as Not Constructive by PrismaticFruits, ScuffedAI, JesseSong, and SoftlockedUnderZero

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

1 answer

Log in to vote
-1
Answered by
JesseSong 3916 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

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

01local script1 = script.Parent -- Defining the function
02local frame = script1.Frame
03local sound = Instance.new ("Sound",script1)
05local humanoid = game.Players.LocalPlayer.Character.Humanoid
06 
07--this function below fires whenever the humanoid's health changes.
08--It also gets the health of the user at that time. (inside the parentheses)
09humanoid.HealthChanged:connect(function(health)
10    if script1.recentUserHP.Value > health then
11    --this asks if the most recent HP logged is higher than the users current HP
12    sound:Play()
13    elseif script1.recentUserHP.Value < health then
14    end
15end)
Ad