local savedValues = DataStore:GetAsync("FolderValues") or "New"
if savedValues == "New" then
print("new")
else
print("existing")
end
How come this works ^
But this will error if it doesn’t exist:
local graves = workspace:WaitForChild("Graves")
function updateGrave(player)
local whichGrave = graves[player.Name] or "New"
if whichGrave == "New" then
print("new")
else
print("old")
end
end
updateGrave(player) -- error -> matt1020304050 is not a valid member of Folder "Workspace.Graves"
Nah, I named the grave to the player’s name. I’m just trying to see if a grave owned by the player exists. I ended up fixing this using a pcall function, but curious why this doesn’t work.
Because in the above statement the result of GetAsync returns a tuple of 2 nil values when key “FolderValues” key does not exist so nil or “New” would result in “New”. In your second example, graves[player.Name] you are trying to access workspace.Graves.matt1020304050 which is not a valid member and is throwing an error. You most likely want this instead:
local whichGrave = graves:FindFirstChild(player.Name) or "New"
No using [] is equivalent to just using a period. The difference is certain things like children whose name start with numbers or contains spaces won’t work with a period and you must use the bracket and quotes.
This is actually not correct. In your first example graves would be a table that is an array and you would need to index it with numbers not strings. Accessing with a string would always result in a nil.