#Beginner Help

1 messages · Page 1 of 1 (latest)

twilit minnow
#

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

What I currently have for the PlayerData: ```local DataStoreModule = require(game.ServerStorage.DataStore)

local template = {
Cherries = 0
}

local function StateChanged(state, dataStore)
while dataStore.State == false do
if dataStore:Open(template) ~= "Success" then task.wait(6) end
end
end

game.Players.PlayerAdded:Connect(function(player)
local dataStore = DataStoreModule.new("Player", player.UserId)
dataStore.StateChanged:Connect(StateChanged)
StateChanged(dataStore.State, dataStore)
end)

game.Players.PlayerRemoving:Connect(function(player)
local dataStore = DataStoreModule.find("Player", player.UserId)
if dataStore ~= nil then dataStore:Destroy() end
end)What I have to spawn cherries;local DataStoreModule = require(game.ServerStorage.DataStore)

while true do
task.wait(5)
local clone = game.ServerStorage.Cherry:Clone()
clone.Position = Vector3.new(math.random(0,100),20,math.random(0,100))
clone.Parent = game.Workspace
clone.Touched:Connect(function(part)
local player = game.Players:GetPlayerFromCharacter(part.Parent)
if player == nil then return end
local dataStore = DataStoreModule.find("Player", player.UserId)
if dataStore == nil then return end
if dataStore.State ~= true then return end
clone:Destroy()
dataStore.Value.Cherries += 1
dataStore.Leaderstats.Cherries.Value = dataStore.Value.Cherries
end)
end```

#

Initally on load in, playerstats did remain at 0, until a cherry was interacted with, I'm currently having an issue where leaderstats doesn't change in the slightest

#

(╯°□°)╯︵ ┻━┻

twilit minnow
#

I think I'm going to have an aneurism

wicked frigate
#

datastore.leaderstats = Leaderstats

#

xd

twilit minnow
#

I saw the first

#

fuckin

#

raging I missed that

wicked frigate
#

all g

#

welcome to programming

twilit minnow
#

Been a here a while, ankle deep

#

All too familiar with the missing comma

#

I need one of those desk duckies to talk to