recently, I have been experimenting with this and haven't found a fix to stop it from repeatedly adding 10 experience since currentXP does not equal the maxXP.
So, how do I deal with this leftover experience I'm getting and how to stop it from exceeding the maxXP limit?
local StarterPlayer = game:GetService("StarterPlayer")
local currentXP = StarterPlayer.plrInfo.currentXP
local currentLevel = StarterPlayer.plrInfo.currentLevel
local maxXP = StarterPlayer.plrInfo.maxXP
touched = true
script.Parent.Touched:Connect(function()
if touched == true then
if currentXP.Value == maxXP.Value then
currentXP.Value =0
currentLevel.Value = currentLevel.Value + 1
maxXP.Value = maxXP.Value*1.5
touched = false
wait(.5)
touched = true
else
currentXP.Value = currentXP.Value + 10
touched = false
wait(.5)
touched = true
end
end
end)
example: I need 188 experience to go on to level 3 but I only get experience in increments of 10, how do I deal with the leftover experience I have?
--
bar gui code:
local StarterPlayer = game:GetService("StarterPlayer")
local currentXP = StarterPlayer.plrInfo.currentXP
local currentLevel = StarterPlayer.plrInfo.currentLevel
local maxXP = StarterPlayer.plrInfo.maxXP
local runService = game:GetService("RunService")
local xpBar = script.Parent.bar
local text = script.Parent.xpStatus
runService.Stepped:connect(function()
text.Text = currentXP.Value.."/"..maxXP.Value.." (lv."..currentLevel.Value..")"
xpBar.Size = UDim2.new((currentXP.Value / maxXP.Value) * 1,0,1,0)
end)

1 comment
https://imgur.com/a/G9SV1I3