Ok I have a Mana Bar that has numbers that change. The max Mana number increases by 20 each time the player levels up and the Mana number is supposed to move up and down (as its used)... but neither numbers are working, they dont even appear. The only number that's appearing is the number I put into the text label. (# is 0) There is nothing in the output so I have no idea what's going on... Help would be really appreciated! (Please don't give me useless answers...) Here is the script:
local Player = game.Players.LocalPlayer local Mana = Player.Leaderstats.Mana local MaxMana = Player.Leaderstats.MaxMana local GUI = game.StarterGui.ManaGui.ManaBar game.Players.LocalPlayer.Changed:Connect(function() GUI.CurrentMana.Text = "Mana: " ..Mana.Value.. "/" ..MaxMana.Value GUI.ManLimit.Size = UDim2.new(0, (Mana.Value/MaxMana.Value) * 0, 0 ,20) end)
The reason it's not working is that you are linking your function to the Changed
event of LocalPlayer
. You should be looking for a change in Mana
to update the text, and a change in MaxMana
to update the maximum mana text.
local StarterGui = game:GetService("StarterGui") local player = game.Players.LocalPlayer local leaderstats = player:WaitForChild("Leaderstats") local mana = leaderstats:WaitForChild("Mana") local maxMana = leaderstats:WaitForChild("MaxMana") local manaGui = StarterGui:WaitForChild("ManaGui") local manaBar = manaGui:WaitForChild("ManaBar") local currentMana = gui:WaitForChild("CurrentMana") local manaLimit = gui:WaitForChild("ManLimit") local function updateManaText() currentMana.Text = "Mana: " .. tostring(mana.Value) .. "/" .. tostring(maxMana.Value) manaLimit.Size = UDim2.new(0, (mana.Value / maxMana.Value), 0, 20) end mana.Changed:Connect(updateManaText) maxMana.Changed:Connect(updateManaText)
Also, on line 8, you set the 2nd parameter of UDim2.new() to (Mana.Value / MaxMana.Value) * 0
which always equals 0, because you are multiplying 0 at the end. I removed the multiplication by 0 in the updated script above.
You should use WaitForChild(object name)
to get references to your object otherwise you might be referencing nil
.
Hope this helps :)