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

How do i make a player not be able to level up after they reach a certain level, and xp?

Asked by
oSyM8V3N 429 Moderation Voter
6 years ago

This is the script :

game.Players.PlayerAdded:connect(function(Player)
    local Data = Instance.new("IntValue",Player) 
    Data.Name = "Data" 
    local XP = Instance.new("IntValue",Data) 
    XP.Name = "XP" 
    XP.Value = 0
    local Level = Instance.new("IntValue",Data) 
    Level.Name = "Level" ------- It's name is Level
    Level.Value = 1 

    XP.Changed:connect(function() XPChange(Player,XP,Level) end) 

end)

function XPChange(Player,XP,Level) 
    if XP.Value >= Level.Value*150  then 
        XP.Value = 0 
        Level.Value = Level.Value+ 1
    end
    if Level.Value == 100 and XP.Value ==15000  then
        --How do i make it so if the XP is 15000 they can't level up if they reach the maxXP
    end
end

1 answer

Log in to vote
0
Answered by
T0XN 276 Moderation Voter
6 years ago
Edited 5 years ago

Just make sure to only do a level change not only if the player's XP is greater than/equal to the Level*150, but also if the level is less than 150. Also it is preferable if you make Data a folder and not an intValue.

game.Players.PlayerAdded:Connect(function(Player)
    local Data = Instance.new('Folder') 
    Data.Name = 'Data'
    Data.Parent = Player
    local XP = Instance.new('IntValue') 
    XP.Name = 'XP' 
    XP.Value = 0
    XP.Parent = Data
    local Level = Instance.new('IntValue') 
    Level.Name = 'Level'
    Level.Value = 1
    Level.Parent = Data
    XP.Changed:Connect(function()
        if XP.Value >= Level.Value * 150 and Level.Value < 150 then 
            XP.Value = 0 
            Level.Value = Level.Value + 1
        end
    end)
end)
0
Tip: to save it, use datastores. PyccknnXakep 1225 — 6y
0
Yeah, I didn't include that because OP didn't ask for it. T0XN 276 — 6y
0
This works, thanks and i already have a DataStore script :) oSyM8V3N 429 — 6y
Ad

Answer this question