Datastore not saving but printing that it does

Hello, I have 3 scripts that are saving data when the player leaves and they all print that they saved data but only the leaderstats actually seems to. I’ve tried testing in game and in studio and on a different account, Still doesn’t want to work. I thought this could be because I’m trying to save too much data at the same time or something but I’m really not sure. All the scripts are written pretty much the same just changing the name of the data store and what I’m saving of course. Should I combine all 3 into a single datastore?

image

Scripts:

1

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("MisccStats") 
game.Players.PlayerAdded:Connect(function(Player)
	local MiscStats = Instance.new("Folder", Player)
	MiscStats.Name = "MiscStats"
	local EquippedStand= Instance.new("StringValue", MiscStats)
	EquippedStand.Name = "EquippedStand"
	EquippedStand.Value = 'Basic'
	local EquippedEffect= Instance.new("StringValue", MiscStats)
	EquippedEffect.Name = "EquippedEffect"
	EquippedEffect.Value = 'nil'
	local Tokens = Instance.new('IntValue', MiscStats)
	Tokens.Name = 'Tokens'
    Tokens.Value = 26

	local Data = DataStore:GetAsync(Player.UserId)
	if Data then
		EquippedEffect.Value = Data.EquippedEffect
		EquippedStand.Value = Data.EquippedStand
		Tokens.Value = Data.Tokens
	end
end)

game.Players.PlayerRemoving:Connect(function(Player)
	DataStore:SetAsync(Player.UserId, {
		["EquippedEffect"] = Player.MiscStats.EquippedEffect.Value;
		["EquippedStand"] = Player.MiscStats.EquippedStand.Value;
		["Tokens"] = Player.MiscStats.Tokens.Value;
		})
	print('Saved MiscStats')
end)

2 (This one actually saves)


local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("leaderStats")


game.Players.PlayerAdded:Connect(function(Player)
	local leaderstats = Instance.new("Folder", Player)
	leaderstats.Name = "leaderstats"
	local Donated = Instance.new("IntValue", leaderstats)
	Donated.Name = "Donated"
	Donated.Value = 0
	local Raised = Instance.new("IntValue", leaderstats)
	Raised.Name = "Raised"
	Raised.Value = 0

	local Data = DataStore:GetAsync(Player.UserId)
	if Data then
		Donated.Value = Data.Donated
		Raised.Value = Data.Raised
		print('Found leaderstats data')
	end
end)


game.Players.PlayerRemoving:Connect(function(Player)
	DataStore:SetAsync(Player.UserId, {
		["Donated"] = Player.leaderstats.Donated.Value;
		["Raised"] = Player.leaderstats.Raised.Value;
	})
	print('Saved leaderstats')
end)

local function AddRaised(userID, amount)
	local player = game.Players:GetPlayerByUserId(userID)
	if player then
		DataStore:SetAsync(userID, {
			["Raised"] = player.leaderstats.Raised.Value + amount
		})
		print('Added and saved Raised:'.. amount ..' to '.. player.Name)
	end
end

local function AddDonated(userID, amount)
	local player = game.Players:GetPlayerByUserId(userID)
	if player then
		DataStore:SetAsync(userID, {
			["Donated"] = player.leaderstats.Donated.Value + amount
		})
		print('Added and saved Donated:'.. amount ..' to '.. player.Name)
	end
end

game.ReplicatedStorage.Events.AddValue.Event:Connect(function(userID, amount, stat)
	if stat == "Raised" then
		AddRaised(userID, amount)
	elseif stat == "Donated" then
		AddDonated(userID, amount)
	end
end)

3

local stands = game.ReplicatedStorage:WaitForChild("Assets").Stands
local HttpService = game.HttpService
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("StandInventoryData") 
local RepStorage = game.ReplicatedStorage
local AddStand = RepStorage.Events.AddStand

game.Players.PlayerAdded:Connect(function(Player)
	local OwnedStands = Instance.new("Folder", Player)
	OwnedStands.Name = "OwnedStands"
	local Basic= Instance.new("BoolValue", OwnedStands)
	Basic.Name = "Basic"
	Basic.Value = true
	local Fall= Instance.new("BoolValue", OwnedStands)
	Fall.Name = "Fall"
	Fall.Value = false
	local Stellar= Instance.new("BoolValue", OwnedStands)
	Stellar.Name = "Stellar"
	Stellar.Value = false

	local Data = DataStore:GetAsync(Player.UserId)
	if Data then
		print('Found Data')
		Basic.Value = Data.Basic
		Fall.Value = Data.Fall
			Stellar.Value = Data.Stellar
	end
end)

game.Players.PlayerRemoving:Connect(function(Player)
	DataStore:SetAsync(Player.UserId, {
		["Basic"] = Player.OwnedStands.Basic.Value;
		["Fall"] = Player.OwnedStands.Fall.Value;
		["Stellar"] = Player.OwnedStands.Stellar.Value;
	})
	print('Saved players stands')
end)

I solved this by combining them all into one script and I realized the data the wasn’t saving was being changed on a local script, I changed it to server side and now it works.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.