Is it just a studio problem i know i suck at datastores but ehh
no errors, also none of the warns print.
code:
local ds = game:GetService("DataStoreService")
local https = game:GetService("HttpService")
local url = no.
local function load(plr)
plr:GetAsync(plr.UserId)
end
--code will literally run on tooth picks and gum
local leadstats
local nights
local maxmode
local function save(plr, datavalue)
plr:SetAsync(plr.UserId, datavalue)
end
local function senderror(plr)
end
game.Players.PlayerAdded:Connect(function(plr)
--value mania
leadstats = Instance.new("Folder", plr)
leadstats.Name = "leadstats"
nights = Instance.new("IntValue", leadstats)
nights.Name = "nights"
maxmode = Instance.new("BoolValue", leadstats)
maxmode.Name = "maxmode"
function senderror(plr)
local message = "Something may have went terribly wrong lol ".. plr.UserId.."/"..plr.Name.. " ".. "nights: "..nights.Value.. " maxmode: ".. tostring(maxmode.Value)
local info = {
["embeds"] = {{
["title"] = "Datastore failure",
["description"] = message
}}
}
local encrpyted = https:JSONEncode(info)
https:PostAsync(url, encrpyted)
end
--that took way too long
local s, r
game:BindToClose(function()
for _, vals in pairs(leadstats:GetChildren()) do
s, r = pcall(function()
save(plr, vals.Value)
warn("Saved")
if not s then
warn ("Saving failed")
repeat save(plr, vals.Value) warn("retrying saving") until s
senderror()
end
end)
end
end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
local s, r
s, r = pcall(function()
load(plr)
warn("saved")
if not s then
warn("failed loading")
senderror()
repeat load(plr) warn("Failed retry") until s
end
end)
end)
plr:GetAsync(plr.UserId)
and
plr:SetAsync(plr.UserId, datavalue)
Are wrong. plr is a player object, which in itself has no link to datastores. You have to get a datastore then call SetAsync / GetAsync on the datastore, NOT the player.
local dss = game:GetService("DataStoreService")
local ds = dss:GetDataStore("Data")
local https = game:GetService("HttpService")
local url = no.
local function load(plr)
ds:GetAsync(plr.UserId)
end
--code will literally run on tooth picks and gum
local leadstats
local nights
local maxmode
local function save(plr, datavalue)
ds:SetAsync(plr.UserId, datavalue)
end
local function senderror(plr)
end
game.Players.PlayerAdded:Connect(function(plr)
--value mania
leadstats = Instance.new("Folder", plr)
leadstats.Name = "leadstats"
nights = Instance.new("IntValue", leadstats)
nights.Name = "nights"
maxmode = Instance.new("BoolValue", leadstats)
maxmode.Name = "maxmode"
function senderror(plr)
local message = "Something may have went terribly wrong lol ".. plr.UserId.."/"..plr.Name.. " ".. "nights: "..nights.Value.. " maxmode: ".. tostring(maxmode.Value)
local info = {
["embeds"] = {{
["title"] = "Datastore failure",
["description"] = message
}}
}
local encrpyted = https:JSONEncode(info)
https:PostAsync(url, encrpyted)
end
--that took way too long
local s, r
game:BindToClose(function()
for _, vals in pairs(leadstats:GetChildren()) do
s, r = pcall(function()
save(plr, vals.Value)
warn("Saved")
if not s then
warn ("Saving failed")
repeat save(plr, vals.Value) warn("retrying saving") until s
senderror()
end
end)
end
end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
local s, r
s, r = pcall(function()
load(plr)
warn("saved")
if not s then
warn("failed loading")
senderror()
repeat load(plr) warn("Failed retry") until s
end
end)
end)
crashes studio and doesn’t save due to
I would highly suggest you take a look at Datastore2. It’s a script someone made to manipulate data extremely easily. Here is the link: How to use DataStore2 - Data Store caching and data loss prevention
You will need basic coding knowledge to understand!
The functions are super easy to understand and you won’t have to bash your head against a wall everytime you try to save something
This bit of code is bad
s, r = pcall(function()
save(plr, vals.Value)
warn("Saved")
if not s then
warn ("Saving failed")
repeat save(plr, vals.Value) warn("retrying saving") until s
senderror()
end
end)
end
end)
it will permanently repeat.
Try this modified version in place of it
s, r = pcall(function()
save(plr, vals.Value)
warn("Saved")
end)
if not s then
warn ("Saving failed")
repeat
s, r = pcall(function()
save(plr, vals.Value)
end)
warn("retrying saving") until s
senderror()
end
end)
end
end)
game.Players.PlayerAdded:connect(function(plr)
– Define variables
spawn(function()
local uniquekey = ‘id-’…plr.userId
local leaderstats = Instance.new(‘StringValue’, plr)
local savevalue = Instance.new(‘StringValue’)
leaderstats.Name = ‘Inventory’
savevalue.Parent = leaderstats
savevalue.Name = ‘Aura’
local savevalue = Instance.new(‘StringValue’)
leaderstats.Name = ‘Inventory’
savevalue.Parent = leaderstats
savevalue.Name = ‘ID1’
wait()
LoadData(plr)
– GetAsync
end)
end)
local players = game:GetService(“Players”)
local dataStoreService = game:GetService(“DataStoreService”)
local leaderboardData = dataStoreService:GetDataStore(“IVentury”)
local function Print(message)
end
local function SaveData(player)
if player.userId < 0 then return end
player:WaitForChild(“Inventory”)
wait()
local leaderstats = {}
for i, stat in pairs(player.Inventory:GetChildren()) do
table.insert(leaderstats, {stat.Name, stat.Value})
end
leaderboardData:SetAsync(player.userId, leaderstats)
Print(“Saved “…player.Name…”'s data”)
end
function LoadData(player)
if player.userId < 0 then return end
player:WaitForChild(“Inventory”)
local leaderboardStats = leaderboardData:GetAsync(player.userId)
for i, stat in pairs(leaderboardStats) do
local currentStat = player.Inventory:FindFirstChild(stat[1])
if not currentStat then return end
currentStat.Value = stat[2]
end
Print(“Loaded “…player.Name…”'s data”)
end
players.PlayerRemoving:connect(SaveData)
if SAFE_SAVE then
game.OnClose = function()
for i, player in pairs(players:GetChildren()) do
SaveData(player)
end
wait(1)
end
end
while AUTO_SAVE do
wait(TIME_BETWEEN_SAVES)
for i, player in pairs(players:GetChildren()) do
SaveData(player)
end
end
Here is a proper Datastore/ datasetup you could use.