So I'm following along with the Datastore Module Basics video, and I'm jsut changing small things here and there to make sure I nderstand what's going on, and I've come across an attempt to index nil with 'Cherries' error in the leaderstats script. This error happens consisently on character load.
local keys = {"Cherries"}
local function StateChanged(state, dataStore)
if state ~= true then return end
for index, name in keys do
dataStore.Leaderstats[name].Value = dataStore.Value[name]
end
end
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
for index, name in keys do
local intValue = Instance.new("IntValue")
intValue.Name = name
intValue.Parent = leaderstats
end
local dataStore = DataStoreModule.new("Player", player.UserId)
dataStore.StateChanged:Connect(StateChanged)
end)``` Aside from the Apples being changed to cherries, there's should be no difference in code.
I appreciate any tips and insight.