workspace[game.Players.LocalPlayer.Name]:WaitForChild("Humanoid")
label = script.Parent.TextLabel
debounce = true
local function hurt()
end
workspace[game.Players.LocalPlayer.Name].Humanoid:GetPropertyChangedSignal('Health'):Connect(function()
if debounce == true then
debounce = false
local num = math.random(1,3)
if num == 1 then
label.Text = "BEHIND YOU"
elseif num == 2 then
label.Text = "RUN"
elseif num == 3 then
label.Text = "ITS HERE"
end
script.Parent.LocalScript.Disabled = false
local num = 0
while wait(.01) do
local clone = game.ReplicatedStorage.special:Clone()
clone.Parent=script.Parent
num = num + .01
if num >= .75 then
script.Parent.TextLabel.Text = ""
break
end
end
wait(4)
debounce = true
end
end)
--//Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--//Variabbles
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Frame = script.Parent
local TextLabel = Frame.TextLabel
--//Controls
local debounce = false
local currentHealth = Humanoid.Health
--//Tables
local Messages = {
[1] = "BEHIND YOU",
[2] = "RUN",
[3] = "ITS HERE"
}
--//Functions
Humanoid.HealthChanged:Connect(function(health)
if debounce and currentHealth >= health then
return
end
currentHealth = health
debounce = true
local randomNumber = Random.new():NextInteger(1, 3)
TextLabel.Text = Messages[randomNumber]
Frame.LocalScript.Disabled = false
local number = 0
while task.wait(0.01) do
local Clone = ReplicatedStorage.special:Clone()
Clone.Parent = Frame
number += 0.01
if number >= 0.75 then
TextLabel.Text = ""
break
end
end
debounce = false
end)
PS: The only reason it kept “looping” was because when the humanoid’s health increased, it still played the animation since you didn’t check if they regenerated health instead of lost health.
Try something like this, where the hurtpart gets touched and activates the code.
workspace.hurtpart.Touched:Connect(function(player)
if debounce == true then
debounce = false
local num = math.random(1,3)
if num == 1 then
label.Text = "BEHIND YOU"
elseif num == 2 then
label.Text = "RUN"
elseif num == 3 then
label.Text = "ITS HERE"
end
script.Parent.LocalScript.Disabled = false
local num = 0
while wait(.01) do
local clone = game.ReplicatedStorage.special:Clone()
clone.Parent=script.Parent
num = num + .01
if num >= .75 then
script.Parent.TextLabel.Text = ""
break
end
end
debounce = true
end
end)
The OP is trying to make it so that when the player gets damaged it plays the animation. Making the function only get connected to a single part doesn’t help and is very inefficient. It’s much more dynamic and better if they just connect that function to the humanoid’s health decreasing.