so the script i made is supposed to save a table with items names, and when player joins it should find items from the table in purchasables model (which is a model that has all purchasable items), and put them into purchased model (where bought items are stored) but it surprisingly doesn't work. however im not getting any errors. Heres the script:
local datastore = game:GetService("DataStoreService")
local ds2 = datastore:GetDataStore("DS2")
local purchasables = game.ServerStorage.PURCHASABLES:GetChildren()
game.Players.PlayerAdded:Connect(function(plr)
local success,err = pcall(function()
for i,v in pairs(purchasables) do
if v.Name == val then
v.Parent = game.Workspace.PURCHASED
end
end
end)
if success then
print("Your Items Have Been Loaded.")
else
print("Your Items Loading Has Failed.")
warn(err)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
for i,v in pairs(game.Workspace.PURCHASED:GetChildren()) do
tab,val = {},v.Name
table.insert(tab,val)
end
local success,err = pcall(function()
for i,v in pairs(purchasables) do
ds2:SetAsync(plr.UserId,val)
end
end)
if success then
print("Your Items Have Been Saved.")
else
print("We Got An Error While Saving Your Items.")
warn(err)
end
end)

3 comments
looks even more complicated than data store 2 but ill try it out
w0t...who uses JSONencode in DataStore, like it's so irrelevant to that. The only places i've seen it being used is in Discord Webhooks
@DrDecor the point is it turns the data into JSON, yes its defined in HTTP service, but JSON is not just for HTTP. in fact JSON stands for "JavaScript Object Notation", and plus whether you want to or not, you will have to turn your data into a string before saving it to datastore (or sending it over a network, in your case), which the JSON functions are good at