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.
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.
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)
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.