local H=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local u=require((H:WaitForChild("\080\114\111\106\101\099\116")):WaitForChild("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101"))local z=(require((H:WaitForChild("\080\114\111\106\101\099\116")):WaitForChild("\083\101\114\118\101\114\083\099\114\105\112\116\083\101\114\118\105\099\101"))):GetContext(script)local A=(u:GetResource("\069\120\116\101\114\110\097\108\085\116\105\108\046\078\101\120\117\115\073\110\115\116\097\110\099\101\046\078\101\120\117\115\073\110\115\116\097\110\099\101")):Extend()A:SetClassName("\069\110\101\114\103\121\083\101\114\118\105\099\101")z:SetContextResource(A)function A.LoadPlayer(u,H)local z=Instance.new("\073\110\116\086\097\108\117\101")z.Name="\069\110\101\114\103\121"z.Value=100 z.Parent=H;(coroutine.wrap(function()while H.Parent do z.Value=math.min(z.Value+1,100)wait(.05)end end))()end function A.UseEnergy(z,H,u)local A=H:WaitForChild("\069\110\101\114\103\121")if A.Value<u then return false end A.Value=A.Value-u return true end return A
--[[
TheNexusAvenger

Manages energy for players.
Class is static (should not be created).
--]]

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local ReplicatedStorageProject = require(ReplicatedStorage:WaitForChild("Project"):WaitForChild("ReplicatedStorage"))
local ServerScriptServiceProject = require(ReplicatedStorage:WaitForChild("Project"):WaitForChild("ServerScriptService")):GetContext(script)

local EnergyService = ReplicatedStorageProject:GetResource("ExternalUtil.NexusInstance.NexusInstance"):Extend()
EnergyService:SetClassName("EnergyService")
ServerScriptServiceProject:SetContextResource(EnergyService)



--[[
Initializes the energy for a player.
--]]
function EnergyService:LoadPlayer(Player)
    --Create the energy value.
    local EnergyValue = Instance.new("IntValue")
    EnergyValue.Name = "Energy"
    EnergyValue.Value = 100
    EnergyValue.Parent = Player

    --Set up regeneration.
    coroutine.wrap(function()
        while Player.Parent do
            EnergyValue.Value = math.min(EnergyValue.Value + 1,100)
            wait(0.05)
        end
    end)()
end

--[[
Uses a player's energy. Returns if the enough
energy existed.
--]]
function EnergyService:UseEnergy(Player,Energy)
    --Return if there is not enough energy.
    local EnergyValue = Player:WaitForChild("Energy")
    if EnergyValue.Value < Energy then
        return false
    end

    --Use the energy and return true.
    EnergyValue.Value = EnergyValue.Value - Energy
    return true
end



return EnergyService