Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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)

3 comments

0

Tip: to save it, use datastores.

0

Yeah, I didn't include that because OP didn't ask for it.

0

This works, thanks and i already have a DataStore script :)

This discussion is preserved as it was. New answers, comments, and votes are closed.