Can anyone tell me how to fix this?
Script:
if WoHumanoid and not WoHumanoid.Health >= WoHumanoid.MaxHealth and not Debounces.HealthKit then
Can anyone tell me how to fix this?
Script:
if WoHumanoid and not WoHumanoid.Health >= WoHumanoid.MaxHealth and not Debounces.HealthKit then
You are using not humanoid.Health >= humanoid.MaxHealth try using this
humanoid.Health < humanoid.MaxHealth
ig that’s because of using not
It fixed the error not popping up anymore but now it doesn’t work
If you want to know the entire code:
function Attackies.HealthKit()
Humanoid.WalkSpeed = 0
Humanoid.JumpPower = 0
CreateVelocityPart(Head, .25)
Animations.Idle:Stop()
Animations.HealthKit:Play()
local HealthKit = ReplicatedStorage:WaitForChild('HealthKit'):Clone()
HealthKit.Parent = workspace
local MainKitPart = HealthKit.Main
MainKitPart.CFrame = Head.CFrame * CFrame.new(0,-1.25,-7)
local KitHitbox = HealthKit.Hitbox
spawn(function()
while task.wait() do
local overlapParams = OverlapParams.new()
local partsInPart = workspace:GetPartsInPart(KitHitbox, overlapParams)
for _, part in pairs(partsInPart) do
local WoHumanoid = part.Parent:FindFirstChildWhichIsA('Humanoid')
if not workspace:FindFirstChild('HealthKit') then return end
if WoHumanoid and not WoHumanoid.Health >= WoHumanoid.MaxHealth and not Debounces.HealthKit then
Debounces.HealthKit = true
Heal(part.Parent, 50)
for _, v in pairs(HealthKit:GetChildren()) do
v.Transparency = 1
v.CanCollide = false
v.Anchored = true
if v.Name == 'Main' then
v.ParticleEmitter:Emit(6)
end
end
wait(1)
HealthKit:Destroy()
wait(2)
Debounces.HealthKit = false
end
end
end
end)
end
What do you mean by it doesn’t work?
And what do you want to achieve?
I got that you are making health kit that heals hp of player also mb there is a problem with denounce if it doesn’t work.
And what about this function heal(part.Parent)?
By not working i mean it’s not healing the player or making the health kit transparent, it’s doing nothing (Only the function not the script ofc)
What i want to achieve is to heal a place once he touches the health kit, once it’s touched the health kit dissapears (not destroyed) and heal the player.
The debounce is pretty much fine, i dont see the error from it.
The code for the heal function:
local function Heal(TargetCharacter, Number)
local TargetHumanoid = Character:WaitForChild('Humanoid')
TargetHumanoid:TakeDamage(-Number)
spawn(function()
Notification(TargetCharacter.Head,"+" .. Number,Color3.new(0,1,0))
end)
end
I am wrong. Didn’t read the code properly.
Also looks like everything should be ok if you just put there check if humanoid health lower than his max health but that’s strange that it doesn’t work because in theory it should
I have tried this:
if WoHumanoid and WoHumanoid.Health ~= WoHumanoid.MaxHealth and not Debounces.HealthKit then
The error is gone but the health kit doesn’t heal or do anything either
I would suggest you to use prints before check and in it to check if your check works
Like print the humanoid to check if it exists
Print denounce, humanoid health and max health
Yeah i think im just going to give up and not do it
Is this the entire code? If then, you maybe forgot to define the Debounces.HealthKit
Well no it’s just the function i forgot to edit that, yes i defined it.
if WoHumanoid and not (WoHumanoid.Health >= WoHumanoid.MaxHealth) and not Debounces.HealthKit then
Parenthesis are needed
No error but still it doesn’t work
Separate each conditional and add a print after it to see which one works or not.
if WoHumanoid then
print("pass 1")
if WoHumanoid.Health < WoHumanoid.MaxHealth then
print("pass 2")
if not Debounces.HealthKit then
print("pass 3")
end
end
end
You shouldn’t ever have not in a comparison operation though. not (x >= y) can be re-written as x < y, it’s cleaner and more efficient. The script here has other problems though
Now there’s a new error which is:
attempt to index nil with ‘Health’
I think this is because of
local WoHumanoid = part.Parent:FindFirstChildWhichIsA('Humanoid')
local WoHumanoid = part.Parent:FindFirstChildWhichIsA('Humanoid')
if not workspace:FindFirstChild('HealthKit') then return end
if WoHumanoid then
print('1')
--[[Debounces.HealthKit = true
Heal(part.Parent, 50)
for _, v in pairs(HealthKit:GetChildren()) do
v.Transparency = 1
v.CanCollide = false
v.Anchored = true
if v.Name == 'Main' then
v.ParticleEmitter:Emit(6)
end
end
wait(1)
HealthKit:Destroy()
wait(2)
Debounces.HealthKit = false]]
elseif WoHumanoid.Health < WoHumanoid.MaxHealth then -- there's where the error happens
print('2')
elseif not Debounces.HealthKit then
print('3')
end
local WoHumanoid = part.Parent:FindFirstChildWhichIsA('Humanoid')
if not workspace:FindFirstChild('HealthKit') then return end
if WoHumanoid then
-- If this doesn't pass then, it's nil
print('1')
elseif WoHumanoid.Health < WoHumanoid.MaxHealth then
-- Your code doesn't account for that and continues assuming it exists
print('2')
elseif not Debounces.HealthKit then
print('3')
end
That’s what i did, however i’ve got an error like mentioned above
No I mean, read the comments:
local WoHumanoid = part.Parent:FindFirstChildWhichIsA('Humanoid')
if not workspace:FindFirstChild('HealthKit') then return end
if WoHumanoid then
if WoHumanoid.Health < WoHumanoid.MaxHealth then
-- Check the health here, because it exists
end
print('1')
elseif not Debounces.HealthKit then
print('2')
end