Alright, so I’m trying to make a more customizable health regeneration system from the default one roblox is using, but for some reason whenever any of the :GetPropertyChangedSignals() fire, they just pass nils to the healthRegen() function. Anybody know why this is happening, and so could you please kindly tell the solution to this problem? Thank you.
The error:
local regenRate = 1/100
local playersHealing = {}
local regenStepTime = 1
local runService = game:GetService("RunService")
local plrs = game.Players
function removeItemFromTable(t, i)
for i,v in t do
if v == i then
table.remove(t, i)
break
end
end
end
function healthRegen(hum : Humanoid)
local char = hum.Parent
if table.find(playersHealing, char.Name) ~= nil then return end
if hum.MaxHealth > hum.Health then
table.insert(playersHealing, char.Name)
repeat
if 0.01 > hum.Health then removeItemFromTable(playersHealing, char.Name) return end
if not hum or char.canHealthRegen.Value == false then removeItemFromTable(playersHealing, char.Name) return end
task.wait(regenStepTime)
hum.Health = math.min(hum.Health + regenStepTime*regenRate*hum.MaxHealth, hum.MaxHealth)
until hum.Health >= hum.MaxHealth
removeItemFromTable(playersHealing, char.Name)
end
end
plrs.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local robloxHealthScript = char:WaitForChild("Health")
if robloxHealthScript then
robloxHealthScript:Destroy()
end
local canHealthRegen = Instance.new("BoolValue", char)
canHealthRegen.Name = "canHealthRegen"
canHealthRegen.Value = true
local hum = char:FindFirstChildOfClass("Humanoid")
hum:GetPropertyChangedSignal("Health"):Connect(healthRegen)
hum:GetPropertyChangedSignal("MaxHealth"):Connect(healthRegen)
canHealthRegen:GetPropertyChangedSignal("Value"):Connect(healthRegen)
end)
end)