Hey! I wanted to make a datasaving with two places that loads and saves the boolvalues.
But the script is not working (Script is in the ServerScriptService)
Just really confused why it does not work?!
--// SERVICES
local DataStoreService = game:GetService("DatastoreService")
--// VARS
local ds = DataStoreService:GetDataStore("datatest")
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local RadiopassID = 663864800
local function checkGamePass(player, passID)
local hasPass = false
local success, message = pcall(function()
hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, passID)
end)
if not success then
warn("Error while checking if player has game pass: " .. tostring(message))
return false
end
return hasPass
end
game.Players.PlayerAdded:Connect(function(plr)
print("executed")
local FolderOwned = Instance.new("Folder",plr)
FolderOwned.Name = "ItemsOwned"
local RadioOwned = Instance.new("BoolValue",FolderOwned)
RadioOwned.Name = "RadioOwned"
----------------------------------------------------
local FolderEquiped = Instance.new("Folder", plr)
FolderEquiped.Name = "ItemsEquiped"
local RadioEquiped = Instance.new("BoolValue",FolderEquiped)
RadioEquiped.Name = "RadioEquiped"
local dataofuser = ds:GetAsync(plr.UserId)
if dataofuser ~= nil then -- anything but nil
print("Found data for " .. plr.Name)
RadioOwned.Value = ds[1]
--------------------------------
RadioEquiped.Value = ds[1]
else
print("Replacing no data with new data.")
RadioOwned.Value = false
-------------------------------
RadioEquiped.Value = false
end
if checkGamePass(plr, RadiopassID) then
-- Player owns the game pass
print("Player owns the game pass")
else
-- Player does not own the game pass
print("Player does not own the game pass")
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local datasave = {}
local folderitemsowned = plr:WaitForChild("ItemsOwned")
local folderitemequiped = plr:WaitForChild("ItemsOwned")
table.insert(datasave, folderitemsowned:WaitForChild("RadioOwned").Value)
--------------------------
table.insert(datasave, folderitemequiped:WaitForChild("RadioEquiped").Value)
local success,response = pcall(function()
ds:SetAsync(plr.UserId, datasave)
end)
if success then
print("succesfully saved data of " .. plr.Name)
else
warn(response)
end
end)
Is it possible that you made a little mistake here?
Also, try printing the “datasave” table in the PlayerRemoved function and see if it’s empty before you save it. Do the same when you start to retrieve the data.
--// SERVICES
local DataStoreService = game:GetService("DatastoreService")
--// VARS
local ds = DataStoreService:GetDataStore("datatest")
local RadiopassID = 663864800
local function checkGamePass(player, passID)
local hasPass = false
local success, message = pcall(function()
hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, passID)
end)
if not success then
warn("Error while checking if player has game pass: " .. tostring(message))
return false
end
return hasPass
end
game.Players.PlayerAdded:Connect(function(plr)
print("executed")
local FolderOwned = Instance.new("Folder",plr)
FolderOwned.Name = "ItemsOwned"
local RadioOwned = Instance.new("BoolValue",FolderOwned)
RadioOwned.Name = "RadioOwned"
----------------------------------------------------
local FolderEquiped = Instance.new("Folder", plr)
FolderEquiped.Name = "ItemsEquiped"
local RadioEquiped = Instance.new("BoolValue",FolderEquiped)
RadioEquiped.Name = "RadioEquiped"
local dataofuser = ds:GetAsync(plr.UserId)
if dataofuser ~= nil then -- anything but nil
print("Found data for " .. plr.Name)
RadioOwned.Value = ds[1]
--------------------------------
RadioEquiped.Value = ds[1]
else
print("Replacing no data with new data.")
RadioOwned.Value = false
-------------------------------
RadioEquiped.Value = false
end
if checkGamePass(plr, RadiopassID) then
-- Player owns the game pass
print("Player owns the game pass")
else
-- Player does not own the game pass
print("Player does not own the game pass")
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local datasave = {}
local folderitemsowned = plr:WaitForChild("ItemsOwned")
local folderitemequiped = plr:WaitForChild("ItemsOwned")
table.insert(datasave, folderitemsowned:WaitForChild("RadioOwned").Value)
--------------------------
table.insert(datasave, folderitemequiped:WaitForChild("RadioEquiped").Value)
local success,response = pcall(function()
ds:SetAsync(plr.UserId, datasave)
end)
if success then
print("succesfully saved data of " .. plr.Name)
else
warn(response)
end
end)