I made a function making getting or computing attributes easier!
Just paste it on your script!
function at(o,a)
local Attribute = setmetatable(
{},
{__call = function(t,n) if n == nil then return o:GetAttribute(a)
else o:SetAttribute(a,n) end end;
__unm = function(t) return -o:GetAttribute(a) end;
__add = function(t,v)
if typeof(t) == "number" then return t+o:GetAttribute(a)
else return o:GetAttribute(a)+v end end;
__sub = function(t,v)
if typeof(t) == "number" then return t-o:GetAttribute(a)
else return o:GetAttribute(a)-v end end;
__mul = function(t,v)
if typeof(t) == "number" then return t*o:GetAttribute(a)
else return o:GetAttribute(a)*v end end;
__div = function(t,v)
if typeof(t) == "number" then return t/o:GetAttribute(a)
else return o:GetAttribute(a)/v end end;
__mod = function(t,v)
if typeof(t) == "number" then return t%o:GetAttribute(a)
else return o:GetAttribute(a)%v end end;
__pow = function(t,v)
if typeof(t) == "number" then return t^o:GetAttribute(a)
else return o:GetAttribute(a)^v end end;
})
return Attribute
end
For example:
game.ReplicatedStorage.GameValues:SetAttribute("Time",120)
local Time= at(game.ReplicatedStorage.GameValues,"Time")
print(Time()) --> 120
print(Time+120) --> 240
print(Time/24) --> 5
print(23480+Time) --> 23600
print(Time() == 120) --> true
Time(60) --Set 'Time' attribute to 60
print(Time+23) --> 83
Time(Time+50) --> Add 50 to 'Time' attribute
print(Time()) --> 110
If there are problems which are bad, reply!