Help with leveling system

I’m making a fun game, called rainbow guys, but i’m trying to make a level system, but how do i check every 10 wins that he get’s, your level increase? Like, every time i get 10 wins, my level goes up, how can i do that?

Here’s my script, Kinda:

local Player = game.Players.LocalPlayer

local Level = Player:FindFirstChild("Level")
local Wins = Player.leaderstats:FindFirstChild("Wins")

Wins.Changed:Connect(function(value)
	if value >= 10 then
		Level.Value += 1
		script.Parent.Display.Text = "Level: "..Level.Value
	end
end)
1 Like

I supposes Player.leaderstats:FindFirstChild(“Wins”) is number of victories and that you are couting it right. Then to show the currect level is simple math:

local Player = game.Players.LocalPlayer

local Level = Player:FindFirstChild("Level")
local Wins = Player.leaderstats:FindFirstChild("Wins")

Wins.Changed:Connect(function(value)
	local levelValue =	math. Floor(tonumber(Wins.Value) / 10)
	script.Parent.Display.Text = "Level: "..tostring(levelValue)	
end)

I will respond to you tomorrow, i have to sleep, bye!

Yo, responding, it’s working perfectly man! Tysm! But, what about the wins system? like, i have a value called level, how would i change that every 10 my level value goes up? I don’t think you understand me that well, but i tried :smile:

1 Like

The easy way:

Wins.Changed:Connect(function(value)
	local levelValue =	math. Floor(tonumber(Wins.Value) / 10)
	script.Parent.Display.Text = "Level: "..tostring(levelValue)
	Level.Value = tonumber(levelValue)
end)

That way will update the Level.Value every time a Wins value change. Since the math like 5/10 is 0. But 13/10 is 1, the level will update correctly every win.

Idk why, but sometimes if i change the level value, it just breaks and if i put the value to 1 it just goes to 0 until i put 10, idk why lol, but i don’t think it will be a big thingy or something

@brenorocketstar Just a question, if i make a datastore for the wins, do i need to make for the level too?

In my example you can only change level by changing wins. If you want to change level to 5, you must first change wins to 50, then the level will update in the next win. If you change level but do not update wins the level will go back to the math of wins divided by 10 in the next win.

Yes, you must create a datastore for the level.

Oh, i thought i didn’t need to do that lol

Hey, a question, how would i make a bar, to check the exp?

Well is a lot of work. I dont know how you manage the Screengui. I made for you this example where the function creates a “progress bar” and does all the math for level/exp based on the number of wins. You can play with values but 23 wins get you to level 2 and fill 30% of the bar.

local function createProgressbar(Wins)

	local numberWins = Wins

	local levelValue =	math.floor(tonumber(numberWins) / 10)

	local mathValue = numberWins / 10

	local fractionalValue = mathValue % 1

	-- Create ScreenGui
	local screenGui = Instance.new("ScreenGui")
	screenGui.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")

	-- Position and size of the first frame
	local firstFramePosition = UDim2.new(0.027, 0, 0.927, 0)
	local firstFrameSize = UDim2.new(0, 800, 0, 25)

	-- Create first frame (background)
	local backgroundFrame = Instance.new("Frame")
	backgroundFrame.Size = firstFrameSize
	backgroundFrame.Position = firstFramePosition
	backgroundFrame.BackgroundColor3 = Color3.fromRGB(255, 255, 255) -- White color
	backgroundFrame.BorderSizePixel = 0 -- No border
	backgroundFrame.Parent = screenGui

	local levelTextLabel = Instance.new("TextLabel")
	levelTextLabel.Text = "Your level is : ".. levelValue
	levelTextLabel.Size = UDim2.new(1, 0, 0.5, 0) -- Size of TextLabel (100% width, 50% height)
	levelTextLabel.Position = UDim2.new(0, 0, -0.5, 0) -- Position of TextLabel (-100% from top, aligned with top edge of background frame)
	levelTextLabel.Parent = backgroundFrame

	-- Create second frame (progress bar)
	local progressBar = Instance.new("Frame")

	progressBar.Size = UDim2.new(fractionalValue, 0, 1, 0) 	

	progressBar.Position = UDim2.new(0, 0, 0, 0) -- Position of progress bar frame (aligned with the background frame)
	progressBar.BackgroundColor3 = Color3.fromRGB(0, 255, 0) -- Green color for progress bar
	progressBar.BorderSizePixel = 0 -- No border
	progressBar.Parent = backgroundFrame
	
end

createProgressbar(23)

Now change Wins.Changed code:

Wins.Changed:Connect(function(value)
    createProgressbar(tonumber(Wins.Value))
	local levelValue =	math. Floor(tonumber(Wins.Value) / 10)
	script.Parent.Display.Text = "Level: "..tostring(levelValue)
	Level.Value = tonumber(levelValue)
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.