How To Display Mana Number On GUI?

I have this mana script and I need it to display the number of mana that the user has. It’s always at 0 out of 100 and it’s fully functional put it isn’t showing the number of mana the player has. If someone could please add something to one of my scripts that will fix it, it would be a big help.

image

image

Mana GUI Script:

local bar = script.Parent.ManaFront

local char = game.Players.LocalPlayer.Character
local hum = char:WaitForChild("Humanoid")

local maxMana = hum:WaitForChild("MaxMana")
local mana = hum:WaitForChild("Mana")

mana.Changed:Connect(function()

	local change = mana.Value / maxMana.Value

	bar:TweenSize(UDim2.new(change,0,1,0))

end)

Mana ServerScriptService Script:

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local hum = char:WaitForChild("Humanoid")
		
		local maxmana = Instance.new("IntValue")
		maxmana.Name = "Mana"
		maxmana.Parent = hum
		maxmana.Value = 100
		
		local mana = Instance.new("IntValue")
		mana.Name = "MaxMana"
		mana.Parent = hum
		mana.Value = maxmana.Value
		
	end)
end)

StarterCharacterScripts Mana Regeneration Script:

local char = script.Parent
local hum = char:WaitForChild("Humanoid")

local maxMana = hum:WaitForChild("MaxMana")
local mana = hum:WaitForChild("Mana")

local manaToGain = 15

while wait(2) do

	if mana.Value < maxMana.Value then

		mana.Value += manaToGain

	end

end

Please add whatever you need to one of the scripts to make it work if you can fix this problem.

You will need to set the mana text to the mana value in the mana.Changed

1 Like

you are changing the value on the client… might need to do something about that

Lol thats it i think (character)

Here’s an example:

local bar = script.Parent.ManaFront
local manaText = script.Parent.ManaText  -- Assuming you have a TextLabel named ManaText

local char = game.Players.LocalPlayer.Character
local hum = char:WaitForChild("Humanoid")

local maxMana = hum:WaitForChild("MaxMana")
local mana = hum:WaitForChild("Mana")

local function updateManaDisplay()
	local change = mana.Value / maxMana.Value
	bar:TweenSize(UDim2.new(change, 0, 1, 0))
	manaText.Text = tostring(mana.Value) .. " / " .. tostring(maxMana.Value)
end

mana.Changed:Connect(updateManaDisplay)
maxMana.Changed:Connect(updateManaDisplay)

-- Initialize display
updateManaDisplay()

I would recommend not storing the int value inside of the character as it can be easily exploited, instead put inside of the player (game.Players.player)

2 Likes

I tried this and it did not work. There wasn’t any errors in output, do you know what went wrong?

I don’t notice anything, you’ll have to find where the issue lies by creating different print statements.

Hey Pixel, I looked over your code multiple times and it looked perfect so I was really having trouble figuring out what was wrong. Turns out it was an issue on my part and I had in the GUI instead of the Frame so it was completely my fault. It works perfectly and thank you for helping me.

image

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.