I am using a custom hp value, not Roblox default. Right now my damage sound plays constantly in game when I only want it to play once when the value decreases.
Here is the code inside my HealthSystem script.
local BaseHP = 5
local HP = Instance.new("NumberValue")
HP.Name = "HP"
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
HP.Parent = player
HP.Value = BaseHP
while true do
if HP.Changed then
game.Workspace.SFX.Damage:Play()
wait(0.4)
end
end
end)
end)
This is inside my health ui
HPvalue = script.Parent
while true do
HPvalue.Text = game.Players.LocalPlayer.HP.Value
wait(0.4)
end
Are you sure the HP Value is even changing in the first place, like is the HP Value changing on the client and you’re trying to play this sound on the server
or what
I think that might be it since i’m using a server and local script, the only thing in the local one is to keep the HP ui the same as the value in the player, but I could probably make the server one a local script if I just changed how i reference the player