Saving a boolvalue in a player

this means the game is saving data too frequently.
Is this your only data storing script or?

1 Like

No, I’m saving leaderstats too

So Are you using two different scripts for them?

1 Like

just 1 script for my leaderstats and 1 for this

You dont need to use seperate scripts.
Just use 1 Single script to do both of them.

Can you show your leaderstats Script?

1 Like

actually i already fix on this topic!
How can I stop getting Data Store warnings on my Data store script? - Help and Feedback / Scripting Support - DevForum | Roblox

And i think, why not saving a numbervalue as a boolvalue instead? like you setting value 1 to true and value 0 to false

That’s not the Issue.
BindToClose Just Is Used for when the Server is Closing.

I Already sent A Script with that.
The Issue Here is data is getting saved Multiple times (In Different Scripts).

Simple way to fix is to Use a table containing all the Instances to Save
in a single Script.

Sure just wait one moment ill send it

here you are

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

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

	local Data = DataStore:GetAsync(Player.UserId)
	if Data then
		Cash.Value = Data.Cash 
		Kills.Value = Data.Kills 
	end
end)

game.Players.PlayerRemoving:Connect(function(Player)
	DataStore:SetAsync(Player.UserId, {
		["Cash"] = Player.leaderstats.Cash.Value; 
		["Kills"] = Player.leaderstats.Kills.Value; 
	})
end)
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("playerInstances")

game.Players.PlayerAdded:Connect(function(Player)
	local OwnedSkinsFolder = Instance.new("Folder", Player)
	OwnedSkinsFolder.Name = "OwnedSkins"
	
	local Skull= Instance.new("BoolValue", OwnedSkinsFolder)
	Skull.Name = "Skull"
	Skull.Value = false
	
	local GalaxyWonderer= Instance.new("BoolValue", OwnedSkinsFolder)
	GalaxyWonderer.Name = "GalaxyWonderer"
	GalaxyWonderer.Value = false
	
	-- // Leaderstats 
	
	local Leaderstats = Instance.new("Folder", Player)
	Leaderstats.Name = "leaderstats"
	
	local Cash= Instance.new("IntValue", Leaderstats)
	Cash.Name = "Cash"
	Cash.Value = 0
	
	local Kills= Instance.new("IntValue", Leaderstats)
	Kills.Name = "Kills"
	Kills.Value = 0
	
	local gotData
	local Success,Errormsg = pcall(function()
		gotData = DataStore:GetAsync(Player.UserId)
	end)
	if gotData then
		Kills.Value = gotData.Kills
		Cash.Value = gotData.Cash
		Skull.Value = gotData.Skull
		GalaxyWonderer.Value = gotData.GalaxyWonderer
	else
		print("New Player Joined / No Data")
	end
end)

game.Players.PlayerRemoving:Connect(function(Player)
	local Success,Errormsg = pcall(function()
    DataStore:SetAsync(Player.UserId, {
		["Skull"] = Player.OwnedSkins.Skull.Value; 
		["GalaxyWonderer"] = Player.OwnedSkins.GalaxyWonderer.Value; 
		["Cash"] = Player.leaderstats.Cash.Value;
		["Kills"] = Player.leaderstats.Kills.Value;
	})
     if not Success then warn(Errormsg) end
    end)
end)

game:BindToClose(function()
	if game:GetService("RunService"):IsStudio() then
		wait(1.25)
	else
		for _, localplayer in pairs(game:GetService("Players"):GetPlayers()) do
			local Success, Error = pcall(function()
				DataStore:SetAsync(localplayer.UserId, {
					["Skull"] = localplayer.OwnedSkins.Skull.Value; 
					["GalaxyWonderer"] = localplayer.OwnedSkins.GalaxyWonderer.Value; 
					["Cash"] = localplayer.leaderstats.Cash.Value;
					["Kills"] = localplayer.leaderstats.Kills.Value;
				})
			end)
		end
	end
end)
3 Likes

if gotData and Success then isn’t a good if statement, use if Success then instead since it’s a pcall function…

It worked thank you so much!!!

Hey are the datastores experiencing issues or something because sometimes my stats will save and others it wont.

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

game.Players.PlayerAdded:Connect(function(Player)
	local OwnedSkinsFolder = Instance.new("Folder", Player)
	OwnedSkinsFolder.Name = "OwnedSkins"
	
	local Skull= Instance.new("BoolValue", OwnedSkinsFolder)
	Skull.Name = "Skull"
	Skull.Value = false
	
	local GalaxyWonderer= Instance.new("BoolValue", OwnedSkinsFolder)
	GalaxyWonderer.Name = "GalaxyWonderer"
	GalaxyWonderer.Value = false
	
	-- // Leaderstats 
	
	local Leaderstats = Instance.new("Folder", Player)
	Leaderstats.Name = "leaderstats"
	
	local Cash= Instance.new("IntValue", Leaderstats)
	Cash.Name = "Cash"
	Cash.Value = 0
	
	local Kills= Instance.new("IntValue", Leaderstats)
	Kills.Name = "Kills"
	Kills.Value = 0
	
	local gotData
	local Success,Errormsg = pcall(function()
		gotData = DataStore:GetAsync(Player.UserId)
	end)
	if gotData then
		Kills.Value = gotData.Kills
		Cash.Value = gotData.Cash
		Skull.Value = gotData.Skull
		GalaxyWonderer.Value = gotData.GalaxyWonderer
	else
		print("New Player Joined / No Data")
	end
end)

game.Players.PlayerRemoving:Connect(function(Player)
	local Success,Errormsg = pcall(function()
    DataStore:SetAsync(Player.UserId, {
		["Skull"] = Player.OwnedSkins.Skull.Value; 
		["GalaxyWonderer"] = Player.OwnedSkins.GalaxyWonderer.Value; 
		["Cash"] = Player.leaderstats.Cash.Value;
		["Kills"] = Player.leaderstats.Kills.Value;
	})
     if not Success then warn(Errormsg) end
    end)
end)

game:BindToClose(function()
	if game:GetService("RunService"):IsStudio() then
		wait(1.25)
	else
		for _, localplayer in pairs(game:GetService("Players"):GetPlayers()) do
			local Success, Error = pcall(function()
				DataStore:SetAsync(localplayer.UserId, {
					["Skull"] = localplayer.OwnedSkins.Skull.Value; 
					["GalaxyWonderer"] = localplayer.OwnedSkins.GalaxyWonderer.Value; 
					["Cash"] = localplayer.leaderstats.Cash.Value;
					["Kills"] = localplayer.leaderstats.Kills.Value;
				})
			end)
		end
	end
end)
1 Like

It still wont save sometimes, well most times

well does it print anything in output when it does not save.
It should if it cant save.

1 Like

nope sorry it only prints “nil”

Everything wrapped in a pcall? If not take a look at pcalls and wrap the save data and get data things in one. If data store services ever go down then your game’s data will still save and your game will be fine.

1 Like

I think they were, I’m not too sure tho

1 Like

Well Yea, Everything is In A Pcall.

The Issue Comes in Loading Apparently.
If There is an error Saving, It would print it out but it does not.

That means its erroring while loading or somethin?

2 Likes