I followed theDevKings tutorial on datastores and yet it doesn't work. It could be that my script is outdated as the video is almost a year old.
Here is the script:
local dataStoreService = game:GetService("DataStoreService")
local dataStore1 = dataStoreService:GetDataStore("dataStore1")
local dataStore2 = dataStoreService:GetDataStore("dataStore2")
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder",plr)
leaderstats.Name = "leaderstats"
local Flips = Instance.new("IntValue",leaderstats)
Flips.Name = "Flips"
Flips.Parent = leaderstats
local Money = Instance.new("IntValue",leaderstats)
Money.Name = "Money"
Money.Parent = leaderstats
local userID = "Player_"..plr.UserId
local flipdata
local moneydata
local success, errormessage = pcall(function()
flipdata = dataStore1:GetAsync(userID)
moneydata = dataStore2:GetAsync(userID)
end)
if success then
Flips.Value = flipdata
Money.Value = moneydata
else
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local userID = "Player_"..plr.UserId
local flipdata = plr.leaderstats.Flips.Value
local moneydata = plr.leaderstats.Money.Value
local success, errormessage = pcall(function()
dataStore1:SetAsync(userID, flipdata)
dataStore2:SetAsync(userID, moneydata)
end)
if success then
print("Cool, data saved")
else
print("Not cool, data not saved")
warn(errormessage)
end
end)

3 comments
Is API service off? If that were so, make sure it is on.
yeah it on
I recommend that you make the data store do something in workspace, that way you can go in and actually play it from the roblox player instead of roblox studios. DataStores are hard to work with because its hard to tell if they work. Although there may be a better way to check this.