Regenerating magic gui not working?

This script is to display how much magic you have and change the size of the magic bar depending on the number (number value) but when your magic goes down it stays there and doesn’t increase as it should

Can anyone tell me why

local player = game.Players.LocalPlayer

game["Run Service"].RenderStepped:Connect(function()
    local num = game.Players.LocalPlayer.Character.Magic
    script.Parent.display.Size = UDim2.new(player.Character.Magic.Value/player.Character.Magic.MaxMagic.Value,0,1,0)
    script.Parent.HP.Text = ""..num.Value.."/"..player.Character.Magic.MaxMagic.Value
end)


if player.Character.Magic.MaxMagic.Value > player.Character.Magic.Value then
    repeat wait(0.3)
        player.Character.Magic.Value = player.Character.Magic.Value + 3
    until player.Character.Magic.Value == player.Character.Magic.MaxMagic.Value
end
if player.Character.Magic.Value == player.Character.Magic.MaxMagic.Value then
    player.Character.Magic.Value = player.Character.Magic.MaxMagic.Value
end

First of all instead of using runservice just put a changed even on the magic:

local player = game.Players.LocalPlayer
local magic = player.Character.Magic
magic.Changed:Connect(function()

end)

So then Everytime the magic changes, tween the gui size:

local player = game.Players.LocalPlayer
local magic = player.Character.Magic
magic.Changed:Connect(function()
    script.Parent.display:TweenSize(Udim2.new(magic.Value / magic.MaxMagic.Value, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.25)
end)

Then you can use runservice for the regeneration

game["Run Service"].RenderStepped:Connect(function()
    if player.Character.Magic.MaxMagic.Value > player.Character.Magic.Value then
        repeat wait(0.3)
            magic.Value = player.Character.Magic.Value + 3
        until magic.Value == magic.MaxMagic.Value
    end
end)

So the script should be

local player = game.Players.LocalPlayer
local magic = player.Character.Magic
magic.Changed:Connect(function()
    script.Parent.display:TweenSize(Udim2.new(magic.Value / magic.MaxMagic.Value, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.25)
end)

game:RunService.RenderStepped:Connect(function()
    if player.Character.Magic.MaxMagic.Value > player.Character.Magic.Value then
        repeat wait(0.3)
            magic.Value = player.Character.Magic.Value + 3
        until magic.Value == magic.MaxMagic.Value
    end
end)

I’ve tried adding something to the script because this doesn’t display the numbers of how much magic you have, but it seems to not work why is that?

is not a ["Run Service"] because the service isn’t exist in the game services (the script mean) maybe you can make it like this:

local player = game.Players.LocalPlayer

game.RunService.RenderStepped:Connect(function()
    local num = game.Players.LocalPlayer.Character.Magic
    script.Parent.display.Size = UDim2.new(player.Character.Magic.Value/player.Character.Magic.MaxMagic.Value,0,1,0)
    script.Parent.HP.Text = ""..num.Value.."/"..player.Character.Magic.MaxMagic.Value
end)


if player.Character.Magic.MaxMagic.Value > player.Character.Magic.Value then
    repeat wait(0.3)
        player.Character.Magic.Value = player.Character.Magic.Value + 3
    until player.Character.Magic.Value == player.Character.Magic.MaxMagic.Value
end
if player.Character.Magic.Value == player.Character.Magic.MaxMagic.Value then
    player.Character.Magic.Value = player.Character.Magic.MaxMagic.Value
end

Magicshowing
This is how my script looked. The Number of your magic and the number of your max magic

Magicnotshowing
Now I have tried both of your script’s but the magic does not display at all

You should try to debug you script by putting print functions for example print to check if the values are really being applied and stuff.

When I use a spell, my magic goes down according to how much the spell takes. Since the scripts arent working, my magic will still go down but I won’t be able to see how much is there and it won’t be able to regenerate. I’ve done what you said but nothing shows in the output

This is what it looks like when you use a spell (Sorry for the keyboard and loud sounds)