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

Update function not working?

Asked by
Hasburo 150
8 years ago
game.Players.PlayerAdded:connect(function(player)
        local stats = player:findFirstChild("leaderstats")
        local rank = stats:findFirstChild("Rank")   

    function Update()
    rank.Value = player:GetRoleInGroup(964666)
    while true do wait(5)
    Update()
    end
    end
    end)

It is supposed to update a player's rank when a player joins the server every 5 seconds. "Rank" is a StringValue in leaderstats.

I am not entirely sure what the problem is.

0
Very hard to understand what you mean, are you trying to change his rank whenever his rank in the group changes? disassembling 48 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

TIP: format your code better, E.G:

eventName:connect(function()
    if blah then
        function ye()
            -- code
        end
    end
end)

The problem is that you cannot fire a function inside the same function, change your code to this:

game.Players.PlayerAdded:connect(function(player)
    local stats = player:findFirstChild("leaderstats")
    local rank = stats:findFirstChild("Rank")   
    function Update()
        rank.Value = player:GetRoleInGroup(964666)
    end
    while true do wait(5)
        Update()
    end
end)

EDIT:

It does not wait for stats to exist, so add a new line under Line 1:

repeat wait() until player.leaderstats

Hope I helped :)

~TDP

0
00:59:34.783 - Workspace.Leaderboard.Rank:3: attempt to index local 'stats' (a nil value) Hasburo 150 — 8y
0
easy fix, ill edit TheDeadlyPanther 2460 — 8y
Ad

Answer this question