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 :)

5 comments
Should go "game:GetService("DataStoreService"):GetDataStore("DateStoreName")" https://developer.roblox.com/en-us/api-reference/function/DataStoreService/GetDataStore
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.
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!")
Tysm! I will try this out!
Thanks, it workls