Datastore help needed!

still occur , many player complain losing money i ended up use ds2

1 Like

this yours right? ( if yes ) your game got small visits . so it shouldnt be a problem to change datastore

Yeah, if this was a new project, I could understand using profileservice or ds2, but because it is quite a big game at this point, it would be difficult to switch over.

The old system can be used to copy data to new one.

No, it’s not this one. The game isn’t launched yet. That was just a very early version of it. I am expecting to have quite a lot more visits on the actual launch. Also, how did you find that? lol

1 Like

das what im saying copy old data and save to profile service , no need to set async just use get async and save into profileservice

Hmm. Honestly, I have now idea how I would implement that. I have looked into that but it saves data when it is changed, not when the player leaves. It is much different.

then save data internal and when changed only

I would not recommend doing that. Depending on where the data comes from, it might change n times in a second, which would mean the same amount of saves are produced. SetAsync’s are not unlimited.

No, that is what ds2 and others do. Mine saves on leave, like u can see in my script.

Are you sure the code you sent is the correct one? The key is supposed to be just the player ID but at the end of the warning it shows “Ships”

Wdym? The code I sent is one of 2 scripts that manage saving. The other one is a script that manages spaceship spawning/saving. A seperate datatstore key.

Here is the ship saving system:

--Create folder to contain spawned ships
local spawnedShips = Instance.new("Folder")
spawnedShips.Name = "SpawnedShips"
spawnedShips.Parent = workspace


--Save data when player leaves
local dss = game:GetService("DataStoreService")
local ds = dss:GetDataStore("ShipsDataStore")



function saveData(player)

	local HttpService = game:GetService("HttpService")
	local DataStore   = game:GetService("DataStoreService"):GetDataStore("PlrValues")
	
	local ships = {}
	
	
	for i, ship in pairs(player.Ships:GetChildren()) do
		table.insert(ships, ship.Name)
	end
	
	ds:SetAsync(player.UserId .. "Ships", ships)
end

game.Players.PlayerRemoving:Connect(saveData)
game:BindToClose(function()
	for i, player in pairs(game.Players:GetPlayers()) do
		saveData(player)
	end
end)

game.Players.PlayerAdded:Connect(function(player)

	local shipsFolder = Instance.new("Folder")
	shipsFolder.Name = "Ships"
	shipsFolder.Parent = player
	
	local shipsData = ds:GetAsync(player.UserId .. "Ships") or {}
	
	local HttpService = game:GetService("HttpService")
	local DataStore   = game:GetService("DataStoreService"):GetDataStore("PlrValues")

	for i, ship in pairs(shipsData) do
		if game.ReplicatedStorage.Ships:FindFirstChild(ship) then
			game.ReplicatedStorage.Ships:FindFirstChild(ship):Clone().Parent = shipsFolder
		end
	end
end)


--Buying and spawning of ships
game.ReplicatedStorage.RemoteEvents.ShipEvents:WaitForChild("ShipsRE").OnServerEvent:Connect(function(player, instruction, ship, dealership)
	
	local shipRequest = game.ReplicatedStorage.Ships:FindFirstChild(ship)
	if shipRequest then
		
		if instruction == "BUY" then
			if player.leaderstats.Checks.Value >= shipRequest.Values.PRICE.Value and not player.Ships:FindFirstChild(shipRequest.Name) then
				player.leaderstats.Checks.Value -= shipRequest.Values.PRICE.Value
				shipRequest:Clone().Parent = player.Ships
				game.ReplicatedStorage.RemoteEvents.ShipEvents.Success:FireClient(player)
			elseif player.Ships:FindFirstChild(shipRequest.Name)  then
				print("own")
				game.ReplicatedStorage.RemoteEvents.ShipEvents.AlreadyOwn:FireClient(player)
			elseif player.leaderstats.Checks.Value < shipRequest.Values.PRICE.Value then
				print("<mon")
				game.ReplicatedStorage.RemoteEvents.ShipEvents.InsuffFunds:FireClient(player)
			end
			
		elseif instruction == "SPAWN" then
			if player.Ships:FindFirstChild(shipRequest.Name) then
				
				if spawnedShips:FindFirstChild(player.Name) then 
					spawnedShips[player.Name]:Destroy()
					for i, desc in pairs(workspace.ShipDealerships:GetDescendants()) do
						if desc.Name == player.Name and desc.Parent.Parent.Name == "CaSpawns" then
							desc:Destroy()
						end
					end
				end
				
				local spawnedShip = shipRequest:Clone()
		
				spawnedShip.Name = player.Name
				spawnedShip.CameraPosition:Destroy()
				
				local chosenSpawn = nil
				for i, shipSpawn in pairs(dealership.ShipSpawns:GetChildren()) do
					if #shipSpawn:GetChildren() < 1 then
						chosenSpawn = shipSpawn
						--local takenValue = Instance.new("StringValue")
						--takenValue.Name = player.Name
					    --takenValue.Parent = chosenSpawn
						break
					end
				end
			
				spawnedShip:SetPrimaryPartCFrame(chosenSpawn.CFrame)
				spawnedShip.Parent = spawnedShips
				game.ReplicatedStorage.RemoteEvents.ShipEvents.DisableClick:FireClient(player)
	
			end
		end
	end
end)


--Removing ships when player leaves
game.Players.PlayerRemoving:Connect(function(player)
	if spawnedShips:FindFirstChild(player.Name) then 
		spawnedShips[player.Name]:Destroy()
		for i, desc in pairs(workspace.ShipDealerships:GetDescendants()) do
			if desc.Name == player.Name and desc.Parent.Parent.Name == "ShipSpawns" then
				desc:Destroy()
			end
		end
	end
end)


--Set up dealerships
for i, dealership in pairs(workspace.ShipDealerships:GetChildren()) do
	
	local prompt = Instance.new("ProximityPrompt")
	prompt.ObjectText = "Open Dealership"
	prompt.ActionText = "Manage Your Vehicles"
	prompt.HoldDuration = 0
	prompt.Parent = dealership.PromptHolder
	prompt.Style = Enum.ProximityPromptStyle.Custom
	
	prompt.Triggered:Connect(function(player)
		game.ReplicatedStorage.RemoteEvents.ShipEvents.ShipsRE:FireClient(player, prompt)
	end)
	
	local ships = game.ReplicatedStorage.Ships:GetChildren()
	
	
	
end
1 Like

Ah! I think maybe I found something! Should I save them to 2 different datastores? Right now they are both being saved to the ship datastore!

oh wait, nvm. The first one is called MainDataStore, and the other one is ShipDataStore, should they both be saved to the same datastore?

yeah, the first code wasn’t the right one. It’s with the second thing you sent

Oh ok. What is the problem with that one?

where are you using saveData in the second one?


to shipsDataStore. The first code saves to MainDataStore

However, I did try to set them both to MainDataStore, but it still gave me the warning.