Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Datastore not saving on player leaving, or value changing?

local DS        = game:GetService("DataStoreService")-- Creating DataStores To Save Your Data
local GoldSave  = DS:GetDataStore("GoldSaveSystem")  --

game.Players.PlayerAdded:Connect(function(Player)				  -- When A Player Joins
	local Folder   = Instance.new("Folder",Player)				  -- New Folder Inside Player Called  "leaderstats"
	Folder.Name    = "leaderstats"                				  -- 
	
	local Gold     = Instance.new("IntValue",Folder)			  -- Making A Value Inside The Player Named "Gold"
	Gold.Name      = "Gold"										  --
	Gold.Value     = GoldSave:GetAsync(Player.UserId) or 0		  --
	Gold.Changed:Connect(function()								  -- Saves Their Gold If They Earn Any			
		GoldSave:SetAsync(Player.UserId, Gold.Value)			  --
	end)														  --
	
	 -- If The XP Changes It Will Call The LevelUp Function
end)

game.Players.PlayerRemoving:Connect(function(Player)-- Saving Their Level Value
	 -- Saving Their XP Value
	GoldSave:SetAsync(Player.UserId, Player.leaderstats.Gold.Value)  -- Saving Their Gold Value
end)																 --

So, i have a datastore that is not saving. The loading is working as i went on the DataStore editor and it loads perfectly. But when i edit the data in leaderstats expecting it to save. It goes back to the values i inserted in datastore editor

4 comments

1

Dude. Don't use 3 datastores for different properties. Just save a table value with the properties instead.

0

Is APi service enabled make sure it is and try publishing it.

0

@JesseSong yes my api service is enabled.

1

mate, you literally only need 1 Datastore, you dont need 3

1 answer

I've had the exact same problem with datastores, however, the only one which worked for me was

local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("WaveSaveSystem")

game.Players.PlayerAdded:connect(function(player)
	
	local Wave = Instance.new("IntValue",player)
	Wave.Name = "Diamond"
	Wave.Value = ds:GetAsync(player.UserId) or 1
	Wave.Changed:connect(function()
		ds:SetAsync(player.UserId, Wave.Value)
		
	end)
end)

game.Players.PlayerRemoving:connect(function(player)
	ds:SetAsync(player.UserId, player.Wave.Value)
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.