I'm working on a level system, and it seems to be working pretty smoothly,
Although the coding is probably more inefficient than Roblox 1.0 ;)
However whenever large amounts of Exp are sent to the XP stat I get this error. Console Screenshot
The Script in the workspace that's erring
game.Players.PlayerAdded:connect(function(player)
local stats = Instance.new('Folder', player)
stats.Name = 'leaderstats'
local experience = Instance.new('IntValue', stats)
experience.Name = 'EXP'
experience.Value = 0
local level = Instance.new('IntValue', stats)
level.Name = 'Level'
level.Value = 0
experience.Changed:connect(function()
if math.floor((level.Value + 1)* 1000) <= math.floor(experience.Value) then
level.Value = level.Value + 1
experience.Value = math.floor(experience.Value) - math.floor((level.Value * 1000))
wait()
if math.floor((level.Value + 1)* 1000) <= math.floor(experience.Value) then
level.Value = level.Value + 1
experience.Value = math.floor(experience.Value) - math.floor((level.Value * 1000))
wait()
else
return
end
elseif math.floor((level.Value + 1)* 1000) >= math.floor(experience.Value) then
return
end
end)
end)
Script in startergui handling animation/display
local leaderstats = game.Players.LocalPlayer:WaitForChild('leaderstats')
local xp = leaderstats:WaitForChild('EXP')
local level = leaderstats:WaitForChild('Level')
local nlevel = nil
local CurrLev = script.Parent.Parent.Parent.Frame_EXPBar:WaitForChild("Label_CurrentLevel")
local NextLev = script.Parent.Parent.Parent.Frame_EXPBar:WaitForChild("Label_NextLevel")
local xpBar = script.Parent.Parent.Parent.Frame_EXPBar
local xpBarFill = script.Parent.Parent.Parent.Frame_EXPBar.Frame_EXPBarFill
function update()
local Math = (((level.Value + 1)*1000) - xp.value)/((level.Value + 1)*1000)
xpBarFill:TweenSize(UDim2.new(1-Math,0,1,0),"Out","Quart",.5,true)
if Math >= ((level.Value+1)*1000) then
xpBarFill:TweenSize(UDim2.new(0,0,1,0),"Out","Quart",.5,true)
else
xpBarFill:TweenSize(UDim2.new(1-Math,0,1,0),"Out","Quart",.5,true)
end
CurrLev.Text = level.Value
NextLev.Text = level.Value + 1
end
xp.Changed:connect(function()
update()
end)
level.Changed:connect(function()
update()
end)

1 comment
Line 14 and line 18, it looks like you're modifying experience in an event that detects experience changes. This may be an area of issue another user may help solve.