Hi devs, i got a question since i made a code that basically remakes an entire health system, this system works basically with attributes and the Omeganum module script, my basic problem is that for some unkown reason the hp everytime i level up, or just join is equal to nil and the max hp dosent update with each level, so far i’ve tried seeing if somewhere it prints the hp as nil in the following 3 scripts but with no luck, i even tried to print it in the datastore or chekc there, but as of now i found “nothing” worng anywhere, what do you think i should do?
the codes (3 scrips):
(the levelling system witch is located in server script serivice:
local x = require(game:GetService("ReplicatedStorage").OmegaNum)
local plrs = game:WaitForChild("Players")
local divi = 10000000
plrs.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function()
plr:GetAttributeChangedSignal("XP"):Connect(function()
local xprequired = x.div(x.mul(plr:GetAttribute("LV"),x.pow(10,x.sqrt(92)),5),divi)
plr:SetAttribute("XP_REQUIRED",x.toString(xprequired)) --((n*10^sqrt(92))*5)
if x.meeq(plr:GetAttribute("XP"),plr:GetAttribute("XP_REQUIRED")) then
local newlv = x.add(plr:GetAttribute("LV"),1)
local xp = x.sub(plr:GetAttribute("XP"),plr:GetAttribute("XP_REQUIRED"))
local newmhp = x.mul(plr:GetAttribute("LV"),plr:GetAttribute("MHP"))
plr:SetAttribute("LV",x.toString(newlv))
plr:SetAttribute("XP",x.toString(xp))
plr:SetAttribute("MHP",x.toString(newmhp))
plr:SetAttribute("HP",x.toString(newmhp))
end
end)
plr:GetAttributeChangedSignal("LV"):Connect(function()
local newxprequired = x.div(x.mul(plr:GetAttribute("LV"),x.pow(10,x.sqrt(92)),5),divi)
local newdamage = x.sqrt(plr:GetAttribute("LV"))
plr:SetAttribute("XP_REQUIRED",x.toString(newxprequired)) --((n*10^sqrt(92))*5)
plr:SetAttribute("DAMAGE",x.toString())
plr:SetAttribute("XP",x.toString(0))
end)
end)
end)
The Hp system (when plr have 0 or nil hp) located in character scripts
local name = script.Parent.Name
local plr = game:GetService("Players"):WaitForChild(name)
local x = require(game:GetService("ReplicatedStorage").OmegaNum)
local nilcheck = require(game:GetService("ReplicatedStorage")["Nil Check"])
plr:GetAttributeChangedSignal("HP"):Connect(function()
nilcheck.isnil(plr,x)
if x.leeq(x.toNumber(plr:GetAttribute("HP")),0) or x.toNumber(plr:GetAttribute("HP")) == nil then
script.Parent.Humanoid.Health = 0
local mhp = plr:GetAttribute("MAXHP")
plr:SetAttribute("HP",mhp)
print(plr:GetAttribute("HP"))
end
end)
The Regen system witch also is located in the character scripts:
local name = script.Parent.Name
local character = script.Parent
local player = game:GetService("Players"):WaitForChild(name)
local x = require(game:GetService("ReplicatedStorage").OmegaNum)
local regen_step = 1
local nilcheck = require(game:GetService("ReplicatedStorage")["Nil Check"])
while true do
nilcheck.isnil(player,x)
while x.less(x.toNumber(player:GetAttribute("HP")), x.toNumber(player:GetAttribute("MAXHP"))) do
task.wait(regen_step)
nilcheck.isnil(player,x)
local perc = x.toNumber(x.div(x.toNumber(player:GetAttribute("HP")),x.toNumber(player:GetAttribute("MAXHP"))))
local hp = x.toString(x.mul(x.mul(regen_step,x.toNumber(player:GetAttribute("MAXHP"))),0.01))
local newhp = x.toString(x.add(player:GetAttribute("HP"),x.toString(math.min(x.toNumber(hp),x.toNumber(player:GetAttribute("MAXHP"))))))
character.Humanoid.Health = x.toNumber(x.mul(character.Humanoid.MaxHealth,perc))
player:SetAttribute("HP",newhp)
print(player:GetAttribute("HP"))
if x.more(player:GetAttribute("HP"),player:GetAttribute("MAXHP")) then
player:SetAttribute("HP",player:GetAttribute("MAXHP"))
print(player:GetAttribute("HP"))
end
end
player:GetAttributeChangedSignal("HP"):Wait()
end
Any ideas?