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

How do Increase a players value in the leaderboard?

Asked by 4 years ago

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)
0
while 1 == 1 do game.player.leaderstats.Level.Value = game.player.leaderstats.Level.Value + 1 wait(30) firespear500 12 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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)
0
The last script wouldn't work because you aren't finding any values IAmNotTheReal_MePipe 418 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

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)

Answer this question