I've been working on a stats system in Roblox Studio for the past 3 days. I have a + button that should increase the player's max health. However, I'm facing an issue: after adding stats, the health regeneration stops at 100 instead of the upgraded max health. I even used a 'while true do' loop to print the current health, but it still shows 100 even after upgrading the health. I need help to ensure the health regenerates until it reaches the new max health value.
Here is the health + script:
local player = game.Players.LocalPlayer
local button = script.Parent
local powerLabel = script.Parent.Parent
local powerLevel = 0
local datastore = game:GetService("DataStoreService")
local dataStoreName = "PowerLevelDataStore"
button.MouseButton1Click:Connect(function()
if powerLevel < 1000 then
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
local gpValue = leaderstats:FindFirstChild("GP")
if gpValue and gpValue.Value >= 1 then
gpValue.Value = gpValue.Value - 1
powerLevel = powerLevel + 1
powerLabel.Text = "POWER LVL: " .. tostring(powerLevel)
local humanoid = player.Character:FindFirstChild("Humanoid")
if humanoid then
local currentMaxHealth = humanoid.MaxHealth
humanoid.MaxHealth = currentMaxHealth + 10
humanoid.Health = humanoid.MaxHealth
end
-- Save the power level to the data store
datastore:SetAsync(player.UserId, { powerLevel = powerLevel })
end
end
end
end)
-- Load the power level from the data store
local success, data = pcall(function()
return datastore:GetAsync(player.UserId)
end)
if success and data and data.powerLevel then
powerLevel = data.powerLevel
powerLabel.Text = "POWER LVL: " .. tostring(powerLevel)
end
** You are now Level 2! **