This is my second post today but i am making a game and a inventory system.I just decided to use datastores because its just gonna store int values…
But it doesnt work and i dont really know why it doesnt…
By The Way this is the whole script :
local dss = game:GetService("DataStoreService")
local datastore = dss:GetDataStore("theDiceWip")
local invstore = dss:GetDataStore("inventory")
local function ds(plr)
--save data
local savetable = {
plr.leaderstats.Stars.Value;
plr.leaderstats.Rolls.Value
}
local success,errorMessage = pcall(datastore.SetAsync,datastore,plr.UserId,savetable)
if success then
print("Data of player "..plr.UserId.." has been saved.")
else
print("Failed to save the data of the player"..plr.UserId..".")
end
end
local function ds2(plr)
local invtable = {
plr.PlayerGui.invgui:WaitForChild("common").Value;
plr.PlayerGui.invgui:WaitForChild("rare").Value;
plr.PlayerGui.invgui:WaitForChild("legendary").Value;
plr.PlayerGui.invgui:WaitForChild("superior").Value;
plr.PlayerGui.invgui:WaitForChild("craziest").Value;
plr.PlayerGui.invgui:WaitForChild("maniack").Value;
plr.PlayerGui.invgui:WaitForChild("qmqmqm").Value
}
local success,errorMessage = pcall(datastore.SetAsync,invstore,plr.UserId,invtable)
if success then
print("Inventory of player "..plr.UserId.." has been saved.")
else
print("Failed to save the inventory of the player"..plr.UserId..".")
end
end
--get leaderboard and datastore
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Wait()
local leaderstats = Instance.new("Folder" ,plr)
leaderstats.Name = "leaderstats"
local stars = Instance.new("IntValue",leaderstats)
stars.Name = "Stars"
local rolls = Instance.new("IntValue",leaderstats)
rolls.Name = "Rolls"
local data = nil
local invdata = nil
local success, errorMessage = pcall(function()
data = datastore:GetAsync(plr.UserId)
end)
local success2, errorMessage2 = pcall(function()
invdata = invstore:GetAsync(plr.UserId)
end)
if success and data then
stars.Value = data[1]
rolls.Value = data[2]
else
print("The player ".. plr.UserId.. " has no data.")
warn(errorMessage)
end
if success2 and invdata then
plr.PlayerGui.invgui.common.Value = invdata[1]
plr.PlayerGui.invgui.rare.Value = invdata[2]
plr.PlayerGui.invgui.legendary.Value = invdata[3]
plr.PlayerGui.invgui.superior.Value = invdata[4]
plr.PlayerGui.invgui.craziest.Value = invdata[5]
plr.PlayerGui.invgui.maniack.Value = invdata[6]
plr.PlayerGui.invgui.qmqmqm.Value = invdata[7]
else
print("The player "..plr.UserId.." has no inventory data.")
warn(errorMessage2)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
ds(plr)
ds2(plr)
end)
game:BindToClose(function()
for _, plr in ipairs(game.Players:GetPlayers()) do
task.spawn(ds,plr)
task.spawn(ds2,plr)
end
end)
if you can please help…
its not very important but i really want it to work…