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

Trying to make a DataStore but I get an error, how do I fix this? [SOLVED]

Asked by 4 years ago
Edited 4 years ago

Error: DataStore is not a valid member or DataStoreService

Trying to make a datastore with a stat and team but get an error. Apparently DataStore (A.K.A something I was told to name whatever I wanted to) is not a valid member. Help please.

--code
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService("DataStore") 

local function loadStarterData(Player)
      local leaderstats = Instance.new("Folder")
      leaderstats.Name = "leaderstats"
      leaderstats.Parent = Player

      local Deaths = Instance.new("IntValue")
      Deaths.Name = "Deaths" 
      Deaths.Parent = leaderstats
end

local function loadData(Player)
      local Data

      local s,e pcall(function()
             Data = DataStore:GetAsync("UserId:".. Player.UserId)
      end)
      if s then
            Player.leaderstats.Deaths.Value = Data[1]
            Player.Team = game.Teams[Data[1]]
            print("Loaded ".. Player.Name .."’s data successfully")
      else
            print("Failed to load ".. Player.Name .."’s data")
      end

end

local function saveData(Player)
      local Data = {
         Deaths = 0,
         Team = ""
       }

      Data.Deaths = Player.leaderstats.Deaths.Value
      Data.Team = Player.Team.Name

      local s,e pcall(function()
             DataStore:SetAsync("UserId:".. Player.UserId, Data)
      end)
      if s then
            print("Saved ".. Player.Name .."’s data successfully")
      else
            print("Failed to save ".. Player.Name .."’s data")
      end

end

game.Players.PlayerAdded:Connect(function(Player)
       loadStarterData(Player)
       loadData(Player)    
end)

game.Players.PlayerRemoving:Connect(function(Player)
       saveData(Player)
end)

Thanks :)

0
Should go "game:GetService("DataStoreService"):GetDataStore("DateStoreName")" https://developer.roblox.com/en-us/api-reference/function/DataStoreService/GetDataStore ForeverBrown 356 — 4y
0
You of course can break that into 2 variables like your trying to do in your code but, I don't think there is any reason to unless you are using multiple datastores in 1 script. ForeverBrown 356 — 4y
0
The Problem is line 3. Were you trying to get a data store? If so, then replace it with something like this: DataStoreService:GetDataStore("Name Here!") Tizzel40 243 — 4y
0
Tysm! I will try this out! AidanTES 36 — 4y
0
Thanks, it workls AidanTES 36 — 4y

Answer this question