Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

how to deal with leftover experience?

Asked by
Hydrogyn 155
4 years ago
Edited 4 years ago

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 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

**You can do it like this: **

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 = currentXP.Value - maxXP.Value
            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)

That's should solve your problem

Edited: I just tested it and works for me....

local StarterPlayer = game:GetService("StarterPlayer")

local currentXP = StarterPlayer.plrInfo.currentXP
local currentLevel = StarterPlayer.plrInfo.currentLevel
local maxXP = StarterPlayer.plrInfo.maxXP
currentXP.Changed:Connect(function(newvalue) -- if the newvalue is > the the maxXP
     if newvalue >= maxXP.Value then
    currentLevel.Value = currentLevel.Value +1
    currentXP.Value = currentXP.Value - maxXP.Value
    maxXP.Value = maxXP.Value *1.5
    end
    end)

Insert this script to ServerScriptService and you are good to go

0
the currentXP values goes into the negatives once I hit a number that isn't divisible by 10 Hydrogyn 155 — 4y
0
Can you send another video cuz the imgur one is blury. DragosGames 43 — 4y
0
https://www.roblox.com/games/4515014353/boss-scenario touch the yellow brick for xp and I'm also using the script you've shown Hydrogyn 155 — 4y
0
Code of the xp bar? DragosGames 43 — 4y
View all comments (8 more)
0
if you keep going till you reach level 3 you'll see what I mean Hydrogyn 155 — 4y
0
Still works for me at level 3 + DragosGames 43 — 4y
0
All i want is to see the xp bar code cuz that's the issue DragosGames 43 — 4y
0
how do I make it so it's always the server is always checking if the currentXP is more than the maxXP Hydrogyn 155 — 4y
0
okay I added the bar gui code Hydrogyn 155 — 4y
0
Doesn't work but thanks for trying. gtg anyways Hydrogyn 155 — 4y
Ad

Answer this question