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

How do Increase a players value in the leaderboard?

I've done this and not sure how to add a lvl to a player after 30 seconds. every 30 seconds.


local datastore = game:GetService("DataStoreService"):GetDataStore("")


game.Players.PlayerAdded:connect(function(player)
	local leaderstats = Instance.new("IntValue")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local points = Instance.new("IntValue")
	points.Name = "Level"
	points.Parent = leaderstats

	
	local key = "user-" .. player.userId
	
	local storeditems = datastore:GetAsync(key)
	if storeditems then
		points.Value = storeditems[1] 
		
	else
		local items = {points.Value} 
		datastore:SetAsync(key, items)
	end
end)

game.Players.PlayerRemoving:connect(function(player)
	local items = {player.leaderstats.Level.Value} 
	local key = "user-" .. player.userId
	
	datastore:SetAsync(key, items)
end)

1 comment

0

while 1 == 1 do game.player.leaderstats.Level.Value = game.player.leaderstats.Level.Value + 1 wait(30)

2 answers

✓ Accepted answer

make the scripts a normal/ server script put it in serverscript service. if the first script dosen't work try the 2nd one

game.Players.PlayerAdded:Connect(function(plr)
	local level = plr.leaderstats.Level
	while true do
		level.Value = level.Value + 1
		wait(30)
	end
end)

If the first script dosen't work

game.Players.PlayerAdded:Connect(function(plr)
	local level = plr.leaderstats.Level
	while true do
		level = level + 1
		wait(30)
	end
end)

1 comment

0

The last script wouldn't work because you aren't finding any values

Try adding lines 13 to 16

local datastore = game:GetService("DataStoreService"):GetDataStore("")


game.Players.PlayerAdded:connect(function(player)
    local leaderstats = Instance.new("IntValue")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local points = Instance.new("IntValue")
    points.Name = "Level"
    points.Parent = leaderstats
    	
    while true do
	wait(30)
	points.Value = points.Value + 1
    end

    local key = "user-" .. player.userId

    local storeditems = datastore:GetAsync(key)
    if storeditems then
        points.Value = storeditems[1] 

    else
        local items = {points.Value} 
        datastore:SetAsync(key, items)
    end
end)

game.Players.PlayerRemoving:connect(function(player)
    local items = {player.leaderstats.Level.Value} 
    local key = "user-" .. player.userId

    datastore:SetAsync(key, items)
end)

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