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

How to connect PlayerStatsManager with Leaderboards (Nil Value Error)? [closed]

Asked by 6 years ago
Edited 6 years ago

I'm new to Lua scripting and DataStorage. I have the PlayerStatsManager Script as Shown (Stored in game.ServerStorage) (I have also seen similar questions to mine with little/no responses)

001-- Setup table that we will return to scripts that require the ModuleScript.
002local PlayerStatManager = {}
003 
004-- Create variable for the DataStore.
005local DataStoreService = game:GetService('DataStoreService')
006local playerData = DataStoreService:GetDataStore('PlayerData')
007 
008-- Create variable to configure how often the game autosaves the player data.
009local AUTOSAVE_INTERVAL = 60
010 
011-- Number of times we can retry accessing a DataStore before we give up and create
012-- an error.
013local DATASTORE_RETRIES = 3
014 
015-- Table to hold all of the player information for the current session.
View all 110 lines...

And I'm trying to call that script inside of my leaderboard script, located in game>Workspace>Main>Stats. This is what I have so far, and I'm attempting to reach it by calling Wins.Value = PlayerStatManager:GetData(Player, "Wins", 0)

01PlayerStatManager = require(game.ServerStorage.PlayerStatManager)
02 
03game.Players.PlayerAdded:connect(function(Player)
04 
05    -- Folders
06    local Folder = Instance.new("Folder", Player)
07    Folder.Name = 'leaderstats'
08 
09    local settingFolder = Instance.new("Folder", Player)
10    settingFolder.Name = 'PlayerSettings'
11 
12    -- Player
13    local Playing = Instance.new('BoolValue', Player)
14    Playing.Name = 'Playing'
15    Playing.Value = false
View all 36 lines...

I'm new to DataStorage, and keep getting nil value errors. The most recent error reads 18:55:55.154 - ServerStorage.PlayerStatManager:29: attempt to index field '?' (a nil value) I've toggled with this script a little and get different errors, but they all result in this sort of error.

I'm just trying to save and store data right now. Can't get passed this error

Closed as Not Constructive by User#19524

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?