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

Attempt a nil value help?

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

1 comment

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.

1 answer

✓ Accepted answer

"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.

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