I put a number Value inside the player humanoid, and set its value to 100.
I then made a script that is supposed to work, only problem is the numbervalue is not updating.
local mana = char:WaitForChild("Humanoid").ManaVal.Value
local maxMana = char:WaitForChild("Humanoid").MaxMana.Value
if mana < maxMana then
while true do
When I change the Mana value manually and set it to 80, the console keeps printing 100, it seems like it’s not updating in the script.
You’re referencing the Value property immediately, it just sets the value into the variables and doesn’t change it in the numbervalues.
Solution: Reference the Value property yourself so it is able to update the Values accordingly
local mana = char:WaitForChild("Humanoid").ManaVal
local maxMana = char:WaitForChild("Humanoid").MaxMana
if mana.Value < maxMana.Value then
while true do
Simply create a RemoteEvent in ReplicatedStorage, And create a regular script in ServerScriptService with this code
local repStore = game:GetService("ReplicatedStorage")
local remote = repStore:WaitForChild("RemoteEvent")
local char = plr.Character
local hum = char and char:FindFirstChildOfClass("Humanoid")
if not hum then return end
hum.ManaVal.Value -= 10
And then in your Localscript, just add a variable to get the Event from the ReplicatedStorage
local remote = game:GetService("ReplicatedStorage").RemoteEvent
And then fire it when you need to decrement
You don’t have to pass in the localplayer yourself, it does so automatically in this case.
I’d also recommend reading this to help you undersatnd more indepth about RemoteEvents and RemoteFunctions and how in the future if you plan on usign them more, you’d to apply sanity checks if the client has to pass in stuff themselves