How can I limit my mana regen to 100 and not exceed the maximum of 100?

Mana = Stamina

My “MaxMana” is 100
My “Mana” is the same as the “MaxMana”
My RegenMana is 3
I want my Regen to stop until 100 is that it does not exceed over 100

2f5ecf97ed90dc7fd0386c25037474e5

Just add if statement?

if Mana.Value > 100 then
   Mana.Value = 100
end

Add check after increase.

2 Likes

1b9d6a44f8e09a61d806a85f04f7b178

Okay thanks but I have another problem it’s my bar it exceeds

wait(1)
local Mana = game.Players.LocalPlayer.Data:WaitForChild("BarStamina")
local MaxMana = game.Players.LocalPlayer.Data:WaitForChild("MaxStamina")

local hpText = script.Parent.Parent.Stamina

Mana.Changed:Connect(function()
	local change = Mana.Value / (MaxMana.Value)
	
	script.Parent.Bar:TweenSize(UDim2.new(change, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 0.2)
	hpText.Text = math.round(Mana.Value) .. "/" .. MaxMana.Value
end)```
1 Like

clamp the size between 0 and 1

1 Like
script.Parent.Bar:TweenSize(UDim2.new(change, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 0.2)

here?

Strange, should have worked.

(klsakjgkldajkjgkjaklkgklaklgk)

It’s just that my bar goes beyond the limit of the mana bar

with that check you still get 100+ mana

when you calculate the new value of mana.
if that value goes over 100 it needs to be capped at 100.
then you need to update the status

How I can make an uptade status

Mana.Changed:Connect(function(currValue)
	local change = currValue / (MaxMana.Value)
	
	script.Parent.Bar:TweenSize(UDim2.new(change, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 0.2)
	hpText.Text = math.round(currValue) .. "/" .. MaxMana.Value
end)

Maybe that?

Still not working you wanted all the scripts?

Sure ,maybe there will be something.

can you tell us the size of bar initially (before any changes) and the bar after being changed for us

i believe you will have to use math.clamp but I need more info on the sizes.

82e53112364b60fc61d2d448774fe152
5fe71d9b0b757ffa9990ab0f3a9a3348
f88b7aa24a32aad9a8395f39628f05dd
cf2504295b2d914e72acb89d62d5a1b6

You can clamp the value.

math.clamp(YourMana,MinMana,MaxMana)

What script should I put it in and where?

show bar size after you lose and regain mana

wait(1)
local Mana = game.Players.LocalPlayer.Data:WaitForChild("BarStamina")
local MaxMana = game.Players.LocalPlayer.Data:WaitForChild("MaxStamina")

local hpText = script.Parent.Parent.Stamina
local MinMana = 0
local MaxMana = 100

Mana.Changed:Connect(function()
    Mana.Value = math.clamp(ManaValue,MinMana,MaxMana)
	local change = Mana.Value / (MaxMana.Value)
	
	script.Parent.Bar:TweenSize(UDim2.new(change, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 0.2)
	hpText.Text = math.round(Mana.Value) .. "/" .. MaxMana.Value
end)

its meaning what “ManaValue” ?

I said that only for the example.