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

Attempt a nil value help?

Asked by 10 years ago

Workspace.Workspace:6: attempt to index a nil value

function script.UploadScore.OnServerInvoke(player)
    local inv = player:WaitForChild("leaderstats")
    local score = game:GetService("DataStoreService"):GetOrderedDataStore("TopScores")
    score:SetAsync(player.Name, inv:FindFirstChild("Points").Value) -- Line 6
end

This is the script. it's called Workspace for now. I don't know what part is a nil value

0
Apparently it cannot find the DataStore you are referring to, therefore score will become nil, and you cannot call :SetAsync() on a nil, or empty, value. juzzbyXfalcon 155 — 10y

1 answer

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

"Indexing a nil value" occurs when you use . or : on a value that is nil.

Looking at your code, inv is definitely not nil (because it was gotten using WaitForChild, player is definitely not nil.

I believe that score should never be nil.


In this case, is probably accessing inv:FindFirstChild("Points"). That is, there will be an error if inv does not have a child named "Points".


To find out which part is the nil value, of course, you should do debugging yourself, and print out each of the values involved and make sure they are all predictable.

Ad

Answer this question