Hello developers! I am currently trying to make a sound play whenever you take damage from a sound folder, and trying to make it so that if I’m at 15 or less health a custom sound plays when I take damage.
I would also like to make it so that if you have a custom MaxHealth lets say like 500 I want it so that when your at like 150 health the custom sound plays.
Unfortunately, I am not big brain enough for this and I tried my best and if you can help me that would be fantastic!
(Shoutout CoreProgramming for the script)
-- Scripted by CoreProgramming. version 2.0 the old version got leaked not publish my me. Put in StarterPlayer > StarterCharacterScripts
local Char = script.Parent
local Humanoid = Char:WaitForChild("Humanoid")
local HumanoidRootPart = Char:WaitForChild("HumanoidRootPart")
local LastHealth = Humanoid.Health
local SoundsFolder = script:WaitForChild("Sounds")
local LowHealth = script:WaitForChild("LowHealthSound")
local Connection
SoundsFolder.Parent = HumanoidRootPart
SoundsFolder = HumanoidRootPart:FindFirstChild("Sounds")
Humanoid.Died:Connect(function()
Connection:Disconnect()
end)
Connection = Humanoid.HealthChanged:Connect(function()
if Humanoid.Health < LastHealth and Humanoid.Health <= 85 then --and (Humanoid.Health / Humanoid.MaxHealth * 100) <= 15 then
print("kinda full on health")
--print(Humanoid.Health)
local Sounds = SoundsFolder:GetChildren()
local ChosenSound = Sounds[math.random(1,#Sounds)]
if ChosenSound ~= nil then
--local e = Instance.new("Part", game.Workspace)
--ChosenSound.Volume = 1
ChosenSound:Play()
elseif Humanoid.Health < LastHealth and Humanoid.Health >= 15 then
if LowHealth ~= nil then
LowHealth:Play()
print("critically low")
end
end
end
LastHealth = Humanoid.Health
end)
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local SoundsFolder = script:WaitForChild("Sounds")
SoundsFolder.Parent = HumanoidRootPart
local LowHealth = script:WaitForChild("LowHealthSound")
LowHealth.Parent = SoundsFolder
Humanoid.HealthChanged:Connect(function(NewHealth)
if NewHealth > 15 then
local Sounds = SoundsFolder:GetChildren()
local ChosenSound = Sounds[math.random(#Sounds)]
ChosenSound:Play()
elseif NewHealth <= 15 then
LowHealth:Play()
end
end)
Server script version:
local _, Character = nil, script.Parent or script.AncestryChanged:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local SoundsFolder = script:WaitForChild("Sounds")
SoundsFolder.Parent = HumanoidRootPart
local LowHealth = script:WaitForChild("LowHealthSound")
LowHealth.Parent = SoundsFolder
Humanoid.HealthChanged:Connect(function(NewHealth)
if NewHealth > 15 then
local Sounds = SoundsFolder:GetChildren()
local ChosenSound = Sounds[math.random(#Sounds)]
ChosenSound:Play()
elseif NewHealth <= 15 then
LowHealth:Play()
end
end)
Thanks a bunch! I do got another question and it’s that how would I make it so that if I’m dead the sounds volume go to 0 and make it 1 when I’m alive?