Global datastore not resetting, but regular datastore works

Hello, very simple subject, but when i try to change my global datasore to be new, everything when you load in the game is like messed up, but it works fine with a regular datasotr

Can you please elaborate? How are you resetting your Datastores? RemoveAsync,RemoveDatstoreAsync?

I was just changing the datastore name

Maybe providing the script will help

local datastore = game:GetService("DataStoreService")
local Gamedata2 = datastore:GetDataStore("PlrStats9")
local BaseStats = {

	Health = 300;
	Chakra = 10;

	Stamina = 10;

	Mode = 10;
	Defence = 0;
	Strenth = 0;
	Experience = 0;
	ExperienceNeed = 0;
	Level = 1;
	MaxLevel = 100,



}



function saveData(Player,plrStats)

	local DataToSave = {}


	print("Saving Data...")
	for i, data in pairs(plrStats:GetChildren()) do
		DataToSave[i] = data.Value
	end

	Gamedata2:SetAsync(Player.UserId,DataToSave)
	print("Spiritual Data Saved.")



end

game.Players.PlayerAdded:Connect(function(Player)
	local plrStats = Instance.new("Folder",Player)
	plrStats.Name = "PlrStats"

	local Health = Instance.new("NumberValue",plrStats)
	Health.Name = "Health"
	Health.Value = BaseStats.Health

	local Stamina = Instance.new("NumberValue",plrStats)
	Stamina.Name = "Stamina"
	Stamina.Value = BaseStats.Stamina

	local MaxStamina = Instance.new("NumberValue",plrStats)
	MaxStamina.Name = "MaxStamina"
	MaxStamina.Value = BaseStats.Stamina


	local Chakra = Instance.new("NumberValue",plrStats)
	Chakra.Name = "Chakra"
	Chakra.Value = BaseStats.Chakra

	local MaxChakra = Instance.new("NumberValue",plrStats)
	MaxChakra.Name = "MaxChakra"
	MaxChakra.Value = BaseStats.Chakra

	local Mode = Instance.new("NumberValue",plrStats)
	Mode.Name = "Mode"
	Mode.Value = BaseStats.Mode

	local MaxMode = Instance.new("NumberValue",plrStats)
	MaxMode.Name = "MaxMode"
	MaxMode.Value = BaseStats.Mode

	local Blood = Instance.new("NumberValue",plrStats)
	Blood.Name = "Blood"
	Blood.Value = 100

	local MaxBlood = Instance.new("NumberValue",plrStats)
	MaxBlood.Name = "MaxBlood"
	MaxBlood.Value = 100

	local Hunger = Instance.new("NumberValue",plrStats)
	Hunger.Name = "Hunger"
	Hunger.Value = 100

	local MaxHunger = Instance.new("NumberValue",plrStats)
	MaxHunger.Name = "MaxHunger"
	MaxHunger.Value = 100

	local Thirst = Instance.new("NumberValue",plrStats)
	Thirst.Name = "Thirst"
	Thirst.Value = 100

	local MaxThirst = Instance.new("NumberValue",plrStats)
	MaxThirst.Name = "MaxThirst"
	MaxThirst.Value = 100


	local Defence = Instance.new("NumberValue",plrStats)
	Defence.Name = "Defence"
	Defence.Value = BaseStats.Defence


	local Strenth = Instance.new("NumberValue",plrStats)
	Strenth.Name = "Strenth"
	Strenth.Value = BaseStats.Strenth



	local Experience = Instance.new("NumberValue",plrStats)
	Experience.Name = "Experience"
	Experience.Value = BaseStats.Experience

	local Element1 = Instance.new("StringValue", plrStats)
	Element1.Name = "Element1"
	Element1.Value  = "Fire #1"

	local Trait = Instance.new("StringValue", plrStats)
	Trait.Name = "Trait"
	Trait.Value = ""

	local Shirt = Instance.new("StringValue", plrStats)
	Shirt.Name = "Shirt"
	Shirt.Value = "Shirt1"

	local Pants = Instance.new("StringValue", plrStats)
	Pants.Name = "Pants"
	Pants.Value = "Pants1"

	local Hair = Instance.new("StringValue", plrStats)
	Hair.Name = "Hair"
	Hair.Value = "InoHair"

	local BodyColor1 = Instance.new("NumberValue", plrStats)
	BodyColor1.Name = "BodyColor1"
	BodyColor1.Value = 235

	local BodyColor2 = Instance.new("NumberValue", plrStats)
	BodyColor2.Name = "BodyColor2"
	BodyColor2.Value = 175

	local BodyColor3 = Instance.new("NumberValue", plrStats)
	BodyColor3.Name = "BodyColor3"
	BodyColor3.Value = 133

	local HairColor1 = Instance.new("NumberValue", plrStats)
	HairColor1.Name = "HairColor1"
	HairColor1.Value = 235

	local HairColor2 = Instance.new("NumberValue", plrStats)
	HairColor2.Name = "HairColor2"
	HairColor2.Value = 175

	local HairColor3 = Instance.new("NumberValue", plrStats)
	HairColor3.Name = "HairColor3"
	HairColor3.Value = 133

	local TwoHairColor1 = Instance.new("NumberValue", plrStats)
	TwoHairColor1.Name = "TwoHairColor1"
	TwoHairColor1.Value = 235

	local TwoHairColor2 = Instance.new("NumberValue", plrStats)
	TwoHairColor2.Name = "TwoHairColor2"
	TwoHairColor2.Value = 175

	local TwoHairColor3 = Instance.new("NumberValue", plrStats)
	TwoHairColor3.Name = "TwoHairColor3"
	TwoHairColor3.Value = 133

	local Hair2 = Instance.new("StringValue", plrStats)
	Hair2.Name = "Hair2"
	Hair2.Value = "InoHair"

	local HeadBand = Instance.new("StringValue", plrStats)
	HeadBand.Name = "HeadBand"
	HeadBand.Value = "StraitHeadBand"

	local TuckedIn = Instance.new("BoolValue", plrStats)
	TuckedIn.Name = "TuckedIn"
	TuckedIn.Value = true


	local ExperienceNeed = Instance.new("NumberValue",plrStats)
	ExperienceNeed.Name = "ExperienceNeed"
	ExperienceNeed.Value = BaseStats.ExperienceNeed

	local Level = Instance.new("NumberValue",plrStats)
	Level.Name = "Level"
	Level.Value = BaseStats.Level

	local Cash = Instance.new("NumberValue",plrStats)
	Cash.Name = "Cash"
	Cash.Value = BaseStats.Cash

	local NormalSlot1 = Instance.new("StringValue",plrStats)
	NormalSlot1.Name = "NormalSlot1"
	NormalSlot1.Value = "Y"

	local NormalSlot2 = Instance.new("StringValue",plrStats)
	NormalSlot2.Name = "NormalSlot2"
	NormalSlot2.Value = "U"

	local NormalSlot3 = Instance.new("StringValue",plrStats)
	NormalSlot3.Name = "NormalSlot3"
	NormalSlot3.Value = "G"

	local NormalSlot4 = Instance.new("StringValue",plrStats)
	NormalSlot4.Name = "NormalSlot4"
	NormalSlot4.Value = "H"

	local NormalSlot5 = Instance.new("StringValue",plrStats)
	NormalSlot5.Name = "NormalSlot5"
	NormalSlot5.Value = "J"

	local NormalSlot6 = Instance.new("StringValue",plrStats)
	NormalSlot6.Name = "NormalSlot6"
	NormalSlot6.Value = "V"

	local SpecialSlot1 = Instance.new("StringValue",plrStats)
	SpecialSlot1.Name = "SpecialSlot1"
	SpecialSlot1.Value = "C"

	local SpecialSlot2 = Instance.new("StringValue",plrStats)
	SpecialSlot2.Name = "SpecialSlot2"
	SpecialSlot2.Value = "Z"

	local WeaponSlot = Instance.new("StringValue",plrStats)
	WeaponSlot.Name = "WeaponSlot"
	WeaponSlot.Value = "1"

	local ThrowableSlot = Instance.new("StringValue",plrStats)
	ThrowableSlot.Name = "ThrowableSlot"
	ThrowableSlot.Value = "2"

	local ExtraSlot1 = Instance.new("StringValue",plrStats)
	ExtraSlot1.Name = "ExtraSlot1"
	ExtraSlot1.Value = "3"

	local ExtraSlot2 = Instance.new("StringValue",plrStats)
	ExtraSlot2.Name = "ExtraSlot2"
	ExtraSlot2.Value = "4"

	local SpecialAbility1 = Instance.new("StringValue",plrStats)
	SpecialAbility1.Name = "SpecialAbility1"
	SpecialAbility1.Value = "Y"

	local SpecialAbility2 = Instance.new("StringValue",plrStats)
	SpecialAbility2.Name = "SpecialAbility2"
	SpecialAbility2.Value = "U"

	local SpecialAbility3 = Instance.new("StringValue",plrStats)
	SpecialAbility3.Name = "SpecialAbility3"
	SpecialAbility3.Value = "G"

	local SpecialAbility4 = Instance.new("StringValue",plrStats)
	SpecialAbility4.Name = "SpecialAbility4"
	SpecialAbility4.Value = "H"

	local SpecialAbility5 = Instance.new("StringValue",plrStats)
	SpecialAbility5.Name = "SpecialAbility5"
	SpecialAbility5.Value = "J"

	local SpecialAbility6 = Instance.new("StringValue",plrStats)
	SpecialAbility6.Name = "SpecialAbility6"
	SpecialAbility6.Value = "V"

	local SpecialAbility7 = Instance.new("StringValue",plrStats)
	SpecialAbility7.Name = "SpecialAbility7"
	SpecialAbility7.Value = "1"

	local SpecialAbility8 = Instance.new("StringValue",plrStats)
	SpecialAbility8.Name = "SpecialAbility8"
	SpecialAbility8.Value = "2"

	Player.CharacterAdded:Connect(function(Character)
		local Humanoid = Character:WaitForChild("Humanoid")
		Humanoid.MaxHealth = Health.Value
		Humanoid.Health = Health.Value
	end)


	local plrsaves
	pcall (function()
		plrsaves = Gamedata2:GetAsync(Player.UserId)

	end)
	if plrsaves then
		--If player has data
		warn("Player has Stat Data!")
		for i, data in pairs(plrStats:GetChildren()) do

			data.Value = plrsaves[i]

			print (data.Name,":",data.Value)
		end

	else

		--if player doenst have data
		warn("Player has no Stat Data.")
		for i, data in pairs(plrStats:GetChildren()) do

			print (data.Name,":",data.Value)

		end	
	end
	while wait() do
		local extraLevel = Level.Value
		local xpNeed = ((extraLevel * 2)-1) * 100

		ExperienceNeed.Value = xpNeed

		if Level.Value < BaseStats.MaxLevel then
			if Experience.Value >= ExperienceNeed.Value then
				Level.Value = Level.Value + 1
				game.ReplicatedStorage.LevelUpSound:FireClient(Player)
				Experience.Value = Experience.Value - ExperienceNeed.Value
			end
		end
	end


end)

game.Players.PlayerRemoving:Connect(function(Player)
	local PlrStats = Player:WaitForChild("PlrStats")
	saveData(Player,PlrStats)

end)

So with that script everything works, cause you said when using a normal Datastore works fine, and the code with the GlobalDatastore? :GetGlobalDataStore()?

If its working fine with the normal Datastore why you wanna change it to a Global one?

Because i need it to be globally between places

Between games or places?
Normal Datastore is shared within the places of a game, and the Global one across games

If that script you are showing works normally when saving into normal one, it doesnt work if you add the global one too?

local datastore = game:GetService("DataStoreService")
local Gamedata2 = datastore:GetDataStore("PlrStats9")
local GlobalData = datastore:GetGlobalDataStore("PlrStats") -- THE GLOBAL ONE
local BaseStats = {
	Health = 300;
	Chakra = 10;
	Stamina = 10;
	Mode = 10;
	Defence = 0;
	Strenth = 0;
	Experience = 0;
	ExperienceNeed = 0;
	Level = 1;
	MaxLevel = 100,
}

function saveData(Player,plrStats)
	local DataToSave = {}

	print("Saving Data...")
	for i, data in pairs(plrStats:GetChildren()) do
		DataToSave[i] = data.Value
	end

	Gamedata2:SetAsync(Player.UserId,DataToSave)
	GlobalData:SetAsync(Player.UserId,DataToSave) -- SAVE IT TO GLOBAL TOO
	print("Spiritual Data Saved.")

end

When joining for the first time, all of the values get messed up and stuff

But this seemed to have works, so thanks

1 Like

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