You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
A bleeding script
What is the issue? Include screenshots / videos if possible!
Bleeding script not working , only animation works (bleed rate and damage doesn’t work)
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried to look on the Developer Hub, but didn’t find anything.
wait(1)
local character = script.Parent:WaitForChild("Humanoid").Parent
local humanoid = character:WaitForChild("Humanoid")
local val = script.bleeding
local brate = script.BleedRate.Value
local damage = script.Damage.Value
local bleedanim = script.BleedAnim
local track = character.Humanoid:WaitForChild("Animator"):LoadAnimation(bleedanim)
humanoid.HealthChanged:Connect(function()
if humanoid.Health < 20 then
val.Value = true
else
if humanoid.Health > 20 then
end
end
end)
val:GetPropertyChangedSignal("Value"):Connect(function()
if val.Value == true then
track:Play()
local blood = script.Blood:Clone()
blood.Parent = character:WaitForChild("HumanoidRootPart")
blood.Enabled = true
else
if val.Value == false then
track:Stop()
if character.HumanoidRootPart:FindFirstChild("Blood") then
character.HumanoidRootPart.Blood:Destroy()
end
end
end
end)
while wait(brate) do
if val.Value == true then
humanoid:TakeDamage(damage)
local Value = Instance.new("IntValue")
Value.Parent = script.Folder
Value.Name = "You are bleeding, you lost " .. damage.Value .. " blood."
else
if val.Value == false then
return
end
end
end
I can see you’re using wait() instead of task.wait(), please use the second option instead as it’s more optimized & far better than the old wait()
Just keep note that you’re saving Numbers as Variables, and you’re not referring to the actual Instance of the Object (Remove the .Value if you’re planning on changing brate, or damage, etc.)
Instead of using GetPropertyChangedSignal, use the .Changed Event instead specifically for Value Objects, this will only fires when that value of said “Value Object” gets changed, and will fire when necessary
Try and create a couple more local variables, where you can later on reference to keep it purely global (Here’s an example)
local Potato = true
local function F1()
Potato = false
end
F1() -- Call the function
print(Potato) -- Outputs back as "false"
For the main issue on why it’s not working, I think it’s because if you’re changing the damage into something else, it won’t properly update as you’re saving that old Value to whatever it could be, a couple ways to fix this would be to:
Re-define the variable as the new Value every time you change it, which I wouldn’t personally recommend doing
Remove the .Value, and call Humanoid:TakeDamage(damage.Value) whenever necessary
There’s a couple other nitpicks that I’m not gonna get into, but try this and see if it works
task.wait(1)
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local hrp = character:WaitForChild("HumanoidRootPart")
local Animator = humanoid:WaitForChild("Animator")
local Folder = script.Folder
local val = script.bleeding
local brate = script.BleedRate
local damage = script.Damage
local bleedanim = script.BleedAnim
local Blood
local function HealthChanged(NewHealth)
if NewHealth < 20 then
val.Value = true
else
print("Has more than 20 HP:", NewHealth)
end
end
local function Bleed(NewVal)
if NewVal == true then
local Anim = Animator:LoadAnimation(bleedanim)
Anim:Play()
Blood = script.Blood:Clone()
Blood.Enabled = true
Blood.Parent = hrp
while val.Value == true do
Humanoid:TakeDamage(damage.Value)
local V = Instance.new("IntValue")
V.Parent = Folder
V.Name = "You are bleeding, you lost "..damage.Value.." blood."
task.wait(brate.Value)
end
Anim:Stop()
else
if Blood ~= nil then
Blood:Destroy()
end
end
end
Humanoid.HealthChanged:Connect(HealthChanged)
val.Changed:Connect(Bleed)