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 4 years ago
Edited 4 years ago

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

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

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
4 years ago
Edited 4 years ago

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)

Ad