Custom Hp bar Bug

Try printing out a bunch of values and tell me what you find

i did something like this

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		wait()
	print(plr:WaitForChild("GasterVoid"):WaitForChild("LOVE").Value)
	
	plr:WaitForChild("GasterVoid"):WaitForChild("LOVE")
	
	print(plr:WaitForChild("GasterVoid"):WaitForChild("LOVE").Value)
	
    char.Humanoid.MaxHealth = plr.GasterVoid.LOVE.Value*4 + 16

	print(plr:WaitForChild("GasterVoid"):WaitForChild("LOVE").Value)
	
	char.Humanoid.Health = char.Humanoid.MaxHealth
	
	print(plr:WaitForChild("GasterVoid"):WaitForChild("LOVE").Value)
	
	game.ReplicatedStorage.PlayerSpawned:FireClient(plr)
	
	print(plr:WaitForChild("GasterVoid"):WaitForChild("LOVE").Value)
	
    end)
end)

at first it was

and then after i died its printed this

Can you send the script that loads in the gastervoid?

sure, the script placed in stats below MAX_HP

local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("EXPSaveSystem")
local ds2 = datastore:GetDataStore("GOLDSaveSystem")
local ds3 = datastore:GetDataStore("LOVESaveSystem")
local ds4 = datastore:GetDataStore("RESETSaveSystem")
function onXPChanged(plr, EXP, LOVE)
	if EXP.Value >=  (10 + 25*LOVE.Value)  then
		EXP.Value = EXP.Value - (10 + 25*LOVE.Value)
		LOVE.Value = LOVE.Value + 1
	elseif LOVE.Value == 100 then
		if EXP.Value >= LOVE.Value*9999999 then
			EXP.Value = EXP.Value - LOVE.Value*9999999
		end
		end
	end
function onLOVEChanged(plr, EXP, LOVE)
	if LOVE.Value >= 100 then
		LOVE.Value = 100
	end
	end
game.Players.PlayerAdded:connect(function(plr)
 local folder = Instance.new("Folder", plr)
 folder.Name = "GasterVoid"
 local GOLD = Instance.new("IntValue", folder)
 GOLD.Name = "GOLD"
 local EXP = Instance.new("IntValue", folder)
 EXP.Name = "EXP"
 local LOVE = Instance.new("IntValue", folder)
 LOVE.Name = "LOVE"
 LOVE.Value = 1
 local RESET = Instance.new("IntValue", folder)
 RESET.Name = "RESET"

 EXP.Value = ds1:GetAsync(plr.UserId) or 0
 ds1:SetAsync(plr.UserId, EXP.Value)
 GOLD.Value = ds2:GetAsync(plr.UserId) or 0
 ds2:SetAsync(plr.UserId, GOLD.Value)
 RESET.Value = ds4:GetAsync(plr.UserId) or 0
 ds4:SetAsync(plr.UserId, RESET.Value)
 LOVE.Value = ds3:GetAsync(plr.UserId) or 0
 ds3:SetAsync(plr.UserId, LOVE.Value)

	

 	EXP.Changed:connect(function()
    ds1:SetAsync(plr.UserId, EXP.Value)
 	onXPChanged(plr, EXP, LOVE)
	end)
	GOLD.Changed:connect(function()
	ds2:SetAsync(plr.UserId, GOLD.Value)
	end)
	LOVE.Changed:connect(function()
	ds3:SetAsync(plr.UserId, LOVE.Value)
	onLOVEChanged(plr, EXP, LOVE)
	end)
	RESET.Changed:connect(function()
	ds4:SetAsync(plr.UserId, RESET.Value)
	end)
end)

Woah there, first of all, you should only use only 1 datastore. You should never repeat yourself that many times. Check out this playlist by @Wrathsong https://www.youtube.com/playlist?list=PLatbVFCcsDB8jgIzJ3a4_q6CeGnsD0rhf

oh ok, i placed everything in one datastore…
now it does this Screenshot by Lightshot

The reason why it might still read 20 is that by the time the script has fired the client, it hasn’t finished getting the datastore value. Maybe, try waiting a longer time in the server script to see if it will fix the issue because it will only fire to the client once every time the character spawns.

so i have to add wait() somewhere? if yes so where??

I would add something like wait(5) to the script where you have the character event and the FireClient() method.

oh hey, it works… but it takes so much time to load, well at least it finally fixed… btw about my data store script… will something bad happen if i leave it like that?

You usually wouldn’t wait for so long, so something like wait(2) could work, but you can use the GetPropertyChangedSignal method when your Health is changed in your local script. I don’t think anything bad will happen, but having multiple datastores storing a single piece of data could be unefficient compared to having one datastore saving a table of information.

thank you so much for helping me, i just found another bug with my hp bar xDD, i’ll save that for another day…