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

Level up System?(Advanced Update help)

Asked by 6 years ago

I apologize for the lack of detail on the title, just no clue as to how I'd name it.

So, I have my Levels in a Modulescript to help with Updates, for a future game that I shallnot disclose yet.

local Level = {}




Level["LevelREQ"] = {
    Level1 = 100;
    level2 = 200;
    level3 = 400;
    level4 = 950;
    level5 = 1550;
    level6 = 2300;
    level7 = 3000;
    level8 = 3900;
    level9 = 5000;
    level10 = 6100;


}


return Level

Which as you can see, has a table of the levels, but the ENTIRE reason of this is to be able to add and remove levels but the way I have the EXPERIENCE system setup COMPLETELy contradicts the purpose of the code.

PlayerEXP.Changed:connect(function()
    if PlayerEXP.Value >= Level.LevelREQ.Level1  then
       PlayerLevel.Value = PlayerLevel.Value + 1
    end

end)

As you can see, it would work perfectly in studio, the problem is, I wish to set it up to the point it just gets the variables from the code, the script sees that the LevelREQ is met, and the level goes up,how it's set up now will only go up 1 level. then stop reading the rest.

1 answer

Log in to vote
0
Answered by
Radstar1 270 Moderation Voter
6 years ago
Edited 6 years ago

I see you aren't sure how to connect your actual level with the module levels. What I can suggest is changing your module's level name to your actual level value.

So for instance, your module says Level1, and you want your .Changed event to recognize you're level 1 and pick the right level in the table. To make life easier change your module's Level1 name to from "Level1" to just "1".

So change the module names to 1,2,3

EX:

local Level = {}

Level["LevelREQ"] = {
    [1] = 100;
    [2] = 200;}

If you change it to that then you can use this code.

PlayerEXP.Changed:Connect(function()
    for  Level,ExpNeeded in pairs(Level["LevelREQ"]) do
        if Level == Player.Level then
            if PlayerEXP.Value >= ExpNeeded then
                PlayerLevel.Value = PlayerLevel.Value + 1
            end
        end
    end
end)

However if you want to use your old code then just do

PlayerEXP.Changed:Connect(function()
    for  Level,ExpNeeded in pairs(Level["LevelREQ"]) do
        if Level == (PlayerLevel.Name..tostring(PlayerLevel.Value)) then
            if PlayerEXP.Value >= ExpNeeded then
                PlayerLevel.Value = PlayerLevel.Value + 1
            end
        end
    end
end)

However I suggest the first part of code because it's cleaner. Accept my answer if it helped, let me know if you have any problems.

0
It did the same thing as before, I did add, player.PlayerData.Level instead of the original position,, other then that, I seem to have quite the issue. Dev_Unreal 136 — 6y
Ad

Answer this question