Was asking you about that. Is it showing tool names now? You’ll need to view F9 if in-game.
Doesn’t print/warn/error anything in the console/output.
oops, i made a mistake…
try this
local dataStoreService = game:GetService("DataStoreService")
local leaderStatStore = dataStoreService:GetDataStore("test7")
local playerInGame = game.Players
playerInGame.PlayerAdded:Connect(function(ourPlayer)
--// L O A D I N G \\--
local dataTableLoad = {};
local playerKey = "Player_"..ourPlayer.UserId
local success, errorMessage = pcall(function()
dataTableLoad = leaderStatStore:GetAsync(playerKey) or {}
end)
if success then
print("Retrieving successful")
for i, v in pairs(dataTableLoad) do
print(i)
print(v.name, v.value)
end
else
print(errorMessage)
end
--[[
if success then
print("successful retrieving data")
local s, e = pcall(function()
for i, v in pairs(dataTableLoad) do
local newPet = Instance.new("StringValue")
newPet.Parent = ourPlayer:WaitForChild("PetInventory")
newPet.Value = v
newPet.Name = i
--v.Value = dataTableLoad[v.Name]
end
end)
else
print("No data, generating new data.")
warn(errorMessage)
end
--]]
end)
playerInGame.PlayerRemoving:Connect(function(ourPlayer)
--// S A V I N G \\--
local playerKey = "Player_"..ourPlayer.UserId
local toSave = {};
if ourPlayer:FindFirstChild("PetInventory") then
for i, v in pairs (ourPlayer.PetInventory:GetChildren())do
table.insert(toSave, {
name = v.Name,
value = v.Value
})
end
end
local success, errorMessage = pcall(function()
leaderStatStore:SetAsync(playerKey, toSave)
end)
if success then
print("Data saving successful")
else
print("Not successful")
warn(errorMessage)
end
end)
Prints out “Retrieving successful” when player joins, and “Successfully processed, no errors!” but doesn’t print out the things you’ve changed.
then…
local dataStoreService = game:GetService("DataStoreService")
local leaderStatStore = dataStoreService:GetDataStore("test7")
local playerInGame = game.Players
playerInGame.PlayerAdded:Connect(function(ourPlayer)
--// L O A D I N G \\--
local dataTableLoad = {};
local playerKey = "Player_"..ourPlayer.UserId
local success, errorMessage = pcall(function()
dataTableLoad = leaderStatStore:GetAsync(playerKey) or {}
end)
if success then
print("Retrieving successful", #dataTableLoad)
for i, v in pairs(dataTableLoad) do
print(i)
print(v.name, v.value)
end
else
print(errorMessage)
end
--[[
if success then
print("successful retrieving data")
local s, e = pcall(function()
for i, v in pairs(dataTableLoad) do
local newPet = Instance.new("StringValue")
newPet.Parent = ourPlayer:WaitForChild("PetInventory")
newPet.Value = v
newPet.Name = i
--v.Value = dataTableLoad[v.Name]
end
end)
else
print("No data, generating new data.")
warn(errorMessage)
end
--]]
end)
playerInGame.PlayerRemoving:Connect(function(ourPlayer)
--// S A V I N G \\--
local playerKey = "Player_"..ourPlayer.UserId
local toSave = {};
if ourPlayer:FindFirstChild("PetInventory") then
for i, v in pairs (ourPlayer.PetInventory:GetChildren())do
table.insert(toSave, {
name = v.Name,
value = v.Value
})
end
end
local success, errorMessage = pcall(function()
print("Saving "..#toSave.." items")
leaderStatStore:SetAsync(playerKey, toSave)
end)
if success then
print("Data saving successful")
else
print("Not successful")
warn(errorMessage)
end
end)
did some debug stuff
Prints out the saving part, all that seems fine. But when it retrieves the items the count is 0
Okay, it should say saving like this
print("Saving "..#toSave.." items")
how many items did it save?
Bought 3 items, it said “Saving 3 items,” then I tested it with 2 items and it said “Saving 2 items.” So that seems to be working fine.
Cool, okay give me a minute. 30chars
now this?
local dataStoreService = game:GetService("DataStoreService")
local leaderStatStore = dataStoreService:GetDataStore("test7")
local playerInGame = game.Players
playerInGame.PlayerAdded:Connect(function(ourPlayer)
--// L O A D I N G \\--
local dataTableLoad = {};
local playerKey = "Player_"..ourPlayer.UserId
local success, errorMessage = pcall(function()
dataTableLoad = leaderStatStore:GetAsync(playerKey)
end)
if success then
print("Retrieving successful", #dataTableLoad)
if dataTableLoad then
for i, v in pairs(dataTableLoad) do
print(i)
print(v.name, v.value)
end
else
print("No data is associated with this player")
end
else
print(errorMessage)
end
--[[
if success then
print("successful retrieving data")
local s, e = pcall(function()
for i, v in pairs(dataTableLoad) do
local newPet = Instance.new("StringValue")
newPet.Parent = ourPlayer:WaitForChild("PetInventory")
newPet.Value = v
newPet.Name = i
--v.Value = dataTableLoad[v.Name]
end
end)
else
print("No data, generating new data.")
warn(errorMessage)
end
--]]
end)
playerInGame.PlayerRemoving:Connect(function(ourPlayer)
--// S A V I N G \\--
local playerKey = "Player_"..ourPlayer.UserId
local toSave = {};
if ourPlayer:FindFirstChild("PetInventory") then
for i, v in pairs (ourPlayer.PetInventory:GetChildren())do
table.insert(toSave, {
name = v.Name,
value = v.Value
})
end
end
local success, errorMessage = pcall(function()
print("Saving "..#toSave.." items")
leaderStatStore:SetAsync(playerKey, toSave)
end)
if success then
print("Data saving successful")
else
print("Not successful")
warn(errorMessage)
end
end)
Line 16 errors with: 13:51:10.038 - ServerScriptService.PetSaveSystem:16: attempt to get length of a nil value
Saving still prints fine
ok noww…
local dataStoreService = game:GetService("DataStoreService")
local leaderStatStore = dataStoreService:GetDataStore("test7")
local playerInGame = game.Players
playerInGame.PlayerAdded:Connect(function(ourPlayer)
--// L O A D I N G \\--
local dataTableLoad = {};
local playerKey = "Player_"..ourPlayer.UserId
local success, errorMessage = pcall(function()
dataTableLoad = leaderStatStore:GetAsync(playerKey)
print("load", dataTableLoad)
end)
if success then
if dataTableLoad then
print("Retrieving successful", #dataTableLoad)
for i, v in pairs(dataTableLoad) do
print(i)
print(v.name, v.value)
end
else
print("No data is associated with this player")
end
else
print(errorMessage)
end
--[[
if success then
print("successful retrieving data")
local s, e = pcall(function()
for i, v in pairs(dataTableLoad) do
local newPet = Instance.new("StringValue")
newPet.Parent = ourPlayer:WaitForChild("PetInventory")
newPet.Value = v
newPet.Name = i
--v.Value = dataTableLoad[v.Name]
end
end)
else
print("No data, generating new data.")
warn(errorMessage)
end
--]]
end)
playerInGame.PlayerRemoving:Connect(function(ourPlayer)
--// S A V I N G \\--
local playerKey = "Player_"..ourPlayer.UserId
local toSave = {};
if ourPlayer:FindFirstChild("PetInventory") then
for i, v in pairs (ourPlayer.PetInventory:GetChildren())do
table.insert(toSave, {
name = v.Name,
value = v.Value
})
end
end
local success, errorMessage = pcall(function()
print("Saving "..#toSave.." items")
leaderStatStore:SetAsync(playerKey, toSave)
end)
if success then
print("Data saving successful")
else
print("Not successful")
warn(errorMessage)
end
end)
Really? Weird. reallly… really weird. this?
local dataStoreService = game:GetService("DataStoreService")
local leaderStatStore = dataStoreService:GetDataStore("test7")
local playerInGame = game.Players
playerInGame.PlayerAdded:Connect(function(ourPlayer)
--// L O A D I N G \\--
local playerKey = "Player_"..ourPlayer.UserId
local success, errorMessage = pcall(function()
local dataTableLoad = leaderStatStore:GetAsync(playerKey)
if dataTableLoad then
print("Retrieving successful", #dataTableLoad)
for i, v in pairs(dataTableLoad) do
print(i)
print(v.name, v.value)
end
else
print("No data is associated with this player")
end
end)
if success then
print(errorMessage)
end
--[[
if success then
print("successful retrieving data")
local s, e = pcall(function()
for i, v in pairs(dataTableLoad) do
local newPet = Instance.new("StringValue")
newPet.Parent = ourPlayer:WaitForChild("PetInventory")
newPet.Value = v
newPet.Name = i
--v.Value = dataTableLoad[v.Name]
end
end)
else
print("No data, generating new data.")
warn(errorMessage)
end
--]]
end)
playerInGame.PlayerRemoving:Connect(function(ourPlayer)
--// S A V I N G \\--
local playerKey = "Player_"..ourPlayer.UserId
local toSave = {};
if ourPlayer:FindFirstChild("PetInventory") then
for i, v in pairs (ourPlayer.PetInventory:GetChildren())do
table.insert(toSave, {
name = v.Name,
value = v.Value
})
end
end
local success, errorMessage = pcall(function()
print("Saving "..#toSave.." items")
leaderStatStore:SetAsync(playerKey, toSave)
end)
if success then
print("Data saving successful")
else
print("Not successful")
warn(errorMessage)
end
end)
Pcall will still catch any errors.
Forgot to create a new datastore, (other than test7) last time. The result for the previous code before the one above is “load nil”
The code above prints out “nil”
Alright, can you try this last one I sent, I think it should work.
Joined :
No data is associated with this player
nil
Left:
Saving 2 items
Joined back:
No data is associated with this player
nil
Wait, so there is no “Data saving successful?”
Nope, didn’t print “Data saving successful”
Works when testing on local server