Need help with a script

I need this script to give the person an amount of points every second.

On line 28 there is a problem with adding a instance value
This is what the error code said in the output: “Players.noah881122.PlayerGui.ScreenGui.Frame.LocalScript:28: attempt to perform arithmetic (add) on Instance and number”
This script is a local script.

local levpro = script.Parent["Level Progress"]
local levnum = script.Parent["Level #"]
local player = script.Parent.Parent.Parent.Parent.Name
local levelgetTo = 10
local levelplayeron = 1
local levvel = 	script.Parent.Parent.Parent.Parent.leaderstats.Level
function level ()

	for i = 0, levelgetTo, 1 do
	script.Parent["Level #"].Text = "level ".. levelplayeron
	levpro.Text = i.."/"..levelgetTo
	wait(math.random(0.35, 1))
	end
	
	levelplayeron = levelplayeron + 1
	script.Parent.Parent.t.Visible = true
	local bc = BrickColor.new("Dark stone grey")
	game.StarterGui:SetCore("ChatMakeSystemMessage", {
		Text = player.."leveled up to level "..levelplayeron;
		Font = Enum.Font.Cartoon;
		Color = bc.Color;
		FontSize = Enum.FontSize.Size96;
		});
	levelgetTo = math.round(levelgetTo * 1.5) 
	chat()
end
function chat()
	levvel.value = levvel +1
	level()

end
level()

That’s because you are adding a number to an instance
Change:

levvel.Value = levvel.Value + 1

The error message indicates that you are trying to perform arithmetic (addition) on an instance and a number. Looking at your code, it seems that the error is occurring on line 28 where you are trying to add a value to levvel.value.

It seems that levvel is an instance of the IntValue class, which means you need to access its Value property to get or set its integer value. Here’s how you can fix the error:

Replace this line:

levvel.value = levvel + 1

with this:

levvel.Value = levvel.Value + 1

This should update the levvel value correctly. Additionally, if you want to give the player an amount of points every second, you can use a while loop to continuously increase the value of levvel.Value and levpro.Text. Here’s an example:

local levpro = script.Parent["Level Progress"]
local levnum = script.Parent["Level #"]
local player = script.Parent.Parent.Parent.Parent.Name
local levelgetTo = 10
local levelplayeron = 1
local levvel = script.Parent.Parent.Parent.Parent.leaderstats.Level

function level()
    while true do
        -- Increment the level value and update the UI
        levvel.Value += 1
        levnum.Text = "Level " .. levelplayeron
        levpro.Text = levvel.Value .. "/" .. levelgetTo

        -- Check if the player has reached the next level
        if levvel.Value >= levelgetTo then
            levelplayeron += 1
            script.Parent.Parent.t.Visible = true
            local bc = BrickColor.new("Dark stone grey")
            game.StarterGui:SetCore("ChatMakeSystemMessage", {
                Text = player.."leveled up to level "..levelplayeron,
                Font = Enum.Font.Cartoon,
                Color = bc.Color,
                FontSize = Enum.FontSize.Size96,
            })
            levelgetTo = math.round(levelgetTo * 1.5)
        end

        wait(1) -- Wait for 1 second before updating again
    end
end

-- Call the level function to start the loop
level()

This code uses a while loop to continuously increase the level value and update the UI every second. It also checks if the player has reached the next level and updates the levelplayeron and levelgetTo variables accordingly.

You code worked but it changed the leaderstat to the amount of points

This code in ServerScriptService:

local dss = game:GetService("DataStoreService")
local levelDS = dss:GetDataStore("Levels")
 
 
function incrementExp(player, increment)
    
    for i = player.Stats.Experience.Value, player.Stats.Experience.Value + increment do
        
        player.Stats.Experience.Value = i
        
        wait()
    end
end
 
 
function saveData(player)
    
    pcall(function()
        
        local level = player.Stats.Level.Value
        local exp = player.Stats.Experience.Value
        
        levelDS:SetAsync(player.UserId .. "Level", {level, exp})
    end)
end
 
 
game.Players.PlayerAdded:Connect(function(player)
    
    
    local statsFolder = Instance.new("Folder", player)
    statsFolder.Name = "leaderstats"
    
    local levelVal = Instance.new("IntValue", statsFolder)
    levelVal.Name = "Level"
    levelVal.Value = 1
    
    local expVal = Instance.new("IntValue", statsFolder)
    expVal.Name = "Experience"
    
    
    pcall(function()
        
        local data = levelDS:GetAsync(player.UserId .. "Level")
        
        if data then
            
            levelVal.Value = data[1]
            expVal.Value = data[2]
        end
    end)
    
    
    expVal:GetPropertyChangedSignal("Value"):Connect(function()
        
        local neededExp = math.floor(levelVal.Value ^ 1.5 + 0.5) * 500
        
        if expVal.Value >= neededExp then
            
            levelVal.Value += 1
        end
    end)
    
    
    while wait(0.2) do
        
        incrementExp(player, 100)
    end
end)
 
 
game.Players.PlayerRemoving:Connect(saveData)
 
game:BindToClose(function()
    
    for i, player in pairs(game.Players:GetPlayers()) do
        
        saveData(player)
    end
end)

Create a ScreenGui And then you together yourself is necessary because of the level


This code in frame:

local clipping = script.Parent:WaitForChild("BarClipping")
clipping.ClipsDescendants = true
 
local expTxt = script.Parent:WaitForChild("Experience")
local levelTxt = script.Parent:WaitForChild("Level")
 
local expVal = game.Players.LocalPlayer:WaitForChild("Stats"):WaitForChild("Experience")
local levelVal = game.Players.LocalPlayer.Stats:WaitForChild("Level")
 
 
local previousExp = expVal.Value
 
 
function updateGui()
    
    local neededExp = math.floor(levelVal.Value ^ 1.5 + 0.5) * 500
    
    local previousLevelExp = math.floor((levelVal.Value - 1) ^ 1.5 + 0.5) * 500
    
    local expDiff = neededExp - previousLevelExp
    
    local currentExp = expVal.Value - previousLevelExp
    
 
    
    local x = currentExp / expDiff
    
    clipping.Size = UDim2.new(x, 0, 1, 0)
    clipping.Bar.Size = UDim2.new(1 / x, 0, 1, 0)
            
    
    expTxt.Text = currentExp .. "/" .. expDiff
    levelTxt.Text = "Level " .. levelVal.Value
    
    
    if expVal.Value == neededExp then
        
        local nextExpNeeded = (math.floor((levelVal.Value + 1) ^ 1.5 + 0.5) * 500) - neededExp
        
        expTxt.Text = "0/" .. nextExpNeeded
        
        levelTxt.Text = "Level " .. levelVal.Value + 1
        
        clipping.Size = UDim2.new(0, 0, 1, 0)
    end
    
    
    previousExp = expVal.Value
end
 
 
updateGui()
 
expVal:GetPropertyChangedSignal("Value"):Connect(updateGui)

local levpro = script.Parent["Level Progress"]
local levnum = script.Parent["Level #"]
local player = script.Parent.Parent.Parent.Parent.Name
local levelgetTo = 10
local levelplayeron = 1
local levvel = 	script.Parent.Parent.Parent.Parent.leaderstats.Level
function level ()

	for i = 0, levelgetTo, 1 do
	script.Parent["Level #"].Text = "level ".. levelplayeron
	levpro.Text = i.."/"..levelgetTo
	wait(math.random(0.35, 1))
	end
	
	levelplayeron = levelplayeron + 1
	script.Parent.Parent.t.Visible = true
	local bc = BrickColor.new("Dark stone grey")
	game.StarterGui:SetCore("ChatMakeSystemMessage", {
		Text = player.."leveled up to level "..levelplayeron;
		Font = Enum.Font.Cartoon;
		Color = bc.Color;
		FontSize = Enum.FontSize.Size96;
		});
	levelgetTo = math.round(levelgetTo * 1.5) 
	chat()
end
function chat()
	levvel.value = levvel +1
	level()

end
level()


if this code is don’t worked try this model: