HP system problems

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?

1 Like

The code seems really complex and hard to understand without knowing your setup and a little more information, but why use a custom health system anyway? There’s already a health system built in, and you can also do regen scripts / increase max health on leveling up with just the default health system built into Roblox.

yes but since i am in basically desperate need to use omeganum i cant use the normal one because of its limitation witch are 5.2 Quintillion, since i didn’t find a solution for that i opted by remaking a new one

It’s still pretty complicated for no reason. Try simplifying it using NumberValues instead of Attributes, etc. and then see if the issue persists.

1 Like

i need to use string values, and i used attributes cuz maily i got tipped by a frined of mine witch is a developer aswell, he basically said since its gonna be a hell of a situation if you make stirng values in a folder why not just use attrributes

It’s more hell to use :GetAttribute() and :SetAttribute() than using 3 NumberValues in a folder. I use NumberValues frequently and it’s much better than using Attributes.

2 Likes

ok, but i can’t use number valuews or the omeganum module willl break

What’s that module supposed to do? If it increases max number values, you don’t need a health system that goes past the normal number limit in studio.

1 Like

i do just dont question why but i do

basically it enables me to do artimetics with big number that are saved in a certain method witch in this case is scientific notation: number(less than 10);the exponetiantion that is supposed to be on the 10

You’re trying to achieve a health system that increases max health when the player levels up. Why use that module then? It’s completely possible without it.

1 Like

i need to use the module because i need to save the value in that way so that when it reached that number it’s gonna autocorrect itself and dosent need my hand to fix it

I still don’t get what you’re trying to achieve while using that module. You don’t need it to make a health system that regenerates and increases on leveling up. And if that is an issue, just… “fix” it by hand. Your code is really messy at the moment, so trying to find the error would take decades. Rather just remake the thing with NumberValues in ~20 minutes. (Also excuse if I don’t understand your point since I’ve never used that module)

1 Like

nah no worries since a very few amount of people use this module i understand that you have 0 idea, i’ll try to explain it briefly, store numbers in strings so you have lots of numbers that you use to do big caltculation not normally able to the “go to number values” the use for this module is mainly cuz you have a more precise calculation and a more variety of numbers, witch is much more than luau (Roblox lua) wich is 1.79e308 ( 1.79 followed by 308 zeroes) thats the why i use it, i know the basicas of the module so im able to use it the moss efficient way as possible by that i mean like x.add (just adding) x.sub(subtracting) x.mul (multiplying x.div ( diving) xlessequal and so much so on

1 Like

to remake it with nubmer values yes i think that would work, but since this hp system is implemente EVERYWHERE i would need to change mobs too

Alright, I’ll look in your code again and try to figure out what’s wrong :+1: I’ll reply back if I find anything.

thanks man that would be heaven if you actually find the problem, thanks

I got one idea, when the player joins you activate the .CharacterAdded function, but the function that sets the start values is only activated when the value changes, right? Maybe that’s the issue?
The code I would do to see if it fixes it:

local x = require(game:GetService("ReplicatedStorage").OmegaNum)
local plrs = game:WaitForChild("Players")
local divi = 10000000
plrs.PlayerAdded:Connect(function(plr)

	plr.CharacterAdded: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)

		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)

Really, it’s an idea, though. If that doesn’t fix it, let me know.

1 Like

but in that code i basically chekc the xp if changes and give a level to the plr if the xp matches the xp required, how would i do both? by both i mean give the values to the playes when he joins in check if the xp matches

Try making a seperate script that does just the level up mechanismus, replace your script that activates when the player joins with the idea I provided, and see if that works. :+1:
If anything doesn’t work, again, just let me know.