I have a boss but I only want the humanoid to go down in health if the value of health goes down,
this is my script to link humanoid health to the value
(I want the value to be the humanoids health and max health but when the value changes I want the humanoids health to be the value of the integer value health)
local health = script.Parent.Health.Value
local boss = script.Parent.Boss
health = boss.MaxHealth
while true do
repeat task.wait(.1) until
boss.Health ~= health
if boss.Health ~= health then
health = boss.Health
end
end
Thats the script that links them together yet it doesn’t work?
He keeps his normal humanoid health without taking the values is there anyway to fix this? Help would of course be appreciated thank you!
With the code you sent, your issue was you defined “health” as the initial value of the Health value. This now becomes a static variable that doesn’t change as it’s now independent from and not associated with the value instance.
Regardless, to improve your code, instead of looping, you can just set a Changed event to listen for the value to change, and then update the humanoid’s health from there.
local health = script.Parent.Health
local boss = script.Parent.Boss
health.Changed:Connect(function(value)
boss.Health = value
end)
handle.Touched:Connect(function(hit)
if attacking and hit.Parent:FindFirstChild("Boss") and hit.Parent:FindFirstChild("Boss"):IsA("Humanoid") then
if not debounce then
debounce = true
hit.Parent.Health.Value -= damage
end
end
end)
I guess you should’t change health.Value try to use this Humanoid:TakeDamage(damage) -- and use this function only from server script.
Also try not to change a variable and then set humanoid health to value. Just use Humanoid.Health and change it.
Why do you need a value if you can directly change humanoid’s health by using humanoid:TakeDamage() in your weapon script.
Hm maybe your humanoid doesn’t take value because it is bigger than it’s maxhealth.
set it’s maxhealth at the start to value.
Cause I have a boss who has 1 hp and I want to check if theres any changes and instead of dealing damage to the boss I want the boss to lower another value instead of taking damage so they dodge instead
Hm try to create a bool value dodge then check if health value below the zero and dodge == false then humanoid:TakeDamage()
local health = script.Parent.Health
local boss = script.Parent.Boss
local dodge = true
health.Changed:Connect(function(value)
if value <= 0 and dodge == false then
boss:TakeDamage(1)
end
end)