Hi, My Name Is Blue, and i have this script that can pick a random sounds in the head, and for some reason its dosent work and i dont really know why,
this is the script
repeat wait() until script.Parent:WaitForChild("HurtSounds"):GetDescendants()
local Humanoid = script.Parent:WaitForChild("Humanoid")
local LastHealth = Humanoid.Health
Humanoid.HealthChanged:Connect(function()
if Humanoid.Health > LastHealth then
LastHealth = Humanoid.Health
end
if Humanoid.Health < LastHealth and LastHealth > 30 then
LastHealth = Humanoid.Health
local Tracks = script.Parent:WaitForChild("Head"):GetDescendants()
local RandomTracks = math.random(1,#Tracks)
local PickedTrack = Tracks[RandomTracks]
if PickedTrack ~= nil then
PickedTrack:Play()
print("im hurt")
end
end
end)

1 comment
at the line 4,the local thingy will always update,so in ur case lasthealth will just show the player's health and always update with player's health