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

Finding a player returns nil, even though the player exists?

Asked by 5 years ago

The main issue here is line 25, it always returns as a nil value for the player.

for i = 1, 25 do
    local Sample = script.Sample:Clone()
    Sample.Name = i
    Sample.Parent = script.Parent.SurfaceGui.Frame.ScrollingFrame
    Sample.UserPos.Text = tostring(i)
    Sample.score.Text = "nan-ind"
    Sample.UserName.Text = ""
    Sample.LayoutOrder = i
    script.Parent.SurfaceGui.Frame.ScrollingFrame.CanvasSize = UDim2.new(0,0,0,50*i)
end
function UpdateGui()
    for i,v in pairs(game.Players:GetChildren()) do
        local Data = tonumber(v.leaderstats["High Score"].Value) --score
        local DS = game:GetService("DataStoreService"):GetOrderedDataStore("Score")
        DS:SetAsync(v.UserId,Data)
    end
    local DS = game:GetService("DataStoreService"):GetOrderedDataStore("Score")
    local Pages = DS:GetSortedAsync(false,25)
    local Data = Pages:GetCurrentPage()
    for k,v in pairs(Data) do
        if tonumber(v.key) >=1 then
            local Frame = script.Parent.SurfaceGui.Frame.ScrollingFrame:FindFirstChild(tostring(k))
            if Frame then
                Frame.UserName.Text = game.Players:GetNameFromUserIdAsync(v.key)
                Frame.score.Text = game.Players:FindFirstChild(Frame.UserName.Text).Name
            end
        end
    end
end

while true do
    UpdateGui()
    wait(5)
end

Why is this happening? I've tried to change Frame.UserName.Text to a few others, but they all returned nil as well, yet when I tried my username, it worked perfectly fine. What's happening?

0
do GetPlayers() HappyTimIsHim 652 — 5y
0
but where? mlgwinners 30 — 5y
0
is it an issue with case? ie you're typing lowercase letters in the textbox, but the players name has a capital in it Gey4Jesus69 2705 — 5y
0
No. mlgwinners 30 — 5y
View all comments (3 more)
0
try enclosing the 'v.key' inside a tonumber(v.key) on line 25 Le_Teapots 913 — 5y
0
Is Frame.score.Text nil? spicychilly2 145 — 5y
0
So all i can think of is you are trying to find a player not in the game or something is wrong with how you are trying to get the players name so couldn''t you just set Frame.score.Text = Frame.UserName.Text? deth836231 142 — 4y

Answer this question