ok i tried my best. so im making an upgraded version of a regular tycoon. heres a script that is supposed to save all things player has purchased into a table, save the table and when he join put items from the table into purchased things. (it doesnt work of course for some reasons, im not getting any errors)

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

0

Have you tried the upgraded DataStore? The DataStore2 version? It cache's players values until they leave so it reduces lag and it's stat loss prevention. It's really useful, try some reasearch about it and it's easier to use as well. Best of luck!

0

i guess ill try it, havent learned about it yet tho

0

I’ve never tried this before, I’ll do a quick research and be back with you