DataStore2 Error HELP

Ok.

Could you show me the part of the script that I need to change then?

I think the isuse is partly related to you using the module in Roblox rather getting the version from GitHub, which may mean you’re using the outdated version. Secondly, there are a few unrelated things such as you making 3 Changed events for the AwardBadge for the coins, which is weird. Also, when you’re changing the values, you’re not changing it from the datastore, you’re changing it from the value in the player, meaning nothing is updating it because you only set an update for when the DataStore is updated

Try this

local DataStore2 = require(1936396537)-- Change this and players Data will be resetted
local serverStorage = game:GetService("ServerStorage")
local MPS = game:GetService("MarketplaceService")
local gamepassID = 9366091
local badgeService = game:GetService("BadgeService")
local badgeID = 2124621453
local CoinsBadge1 = 2124622822
local coinsBadge2 = 2124622824
local coinsBadge3 = 2124622835

DataStore2.Combine("DATA", "Coins", "Gems", "Levels", "Exp", "Rebirths", "NoobPoints")

game.Players.PlayerAdded:Connect(function(player)
	
	local coinsDataStore = DataStore2("Coins", player)
	local gemsDataStore = DataStore2("Gems", player)
	local levelsDataStore = DataStore2("Levels", player)
	local expDataStore = DataStore2("Exp", player)
	local rebirthsDataStore = DataStore2("Rebirths", player)
	local noobDataStore = DataStore2("NoobPoints", player)
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local noob = Instance.new("IntValue")
	noob.Name = "NoobPoints"
	noob.Value = noobDataStore:Get(0)
	noob.Parent = leaderstats
	
	local coins = Instance.new("IntValue")
	coins.Name = "Coins"
	coins.Value = coinsDataStore:Get(0)
	coins.Parent = leaderstats
	
	local gems = Instance.new("IntValue")
	gems.Name = "Gems"
	gems.Value = gemsDataStore:Get(0)
	gems.Parent = leaderstats
	
	local levels = Instance.new("IntValue")
	levels.Name = "Levels"
	levels.Value = levelDataStore:Get(0)
	levels.Parent = leaderstats
	
	local exp = Instance.new("IntValue")
	exp.Name = "Exp"
	exp.Value = expDataStore:Get(0)
	exp.Parent = leaderstats
	
	local rebirths = Instance.new("IntValue")
	rebirths.Name = "Rebirths"
	rebirths.Parent = leaderstats
	rebirths.Value = rebirthsDataStore:Get(0)
	
	if not badgeService:UserHasBadgeAsync(player.UserId, badgeID) then
		badgeService:AwardBadge(player.UserId, badgeID)
	end
	
	coins.Changed:Connect(function(value)
		coinsDataStore:Set(value)
		if value >= 250 then
			if not badgeService:UserHasBadgeAsync(player.UserId, CoinsBadge1) then
				badgeService:AwardBadge(player.UserId, CoinsBadge1)
			end
		end
		if value >= 1500 then
			if not badgeService:UserHasBadgeAsync(player.UserId, coinsBadge2) then
				badgeService:AwardBadge(player.UserId, coinsBadge2)
			end
		end
		if value >= 10000 then
			if not badgeService:UserHasBadgeAsync(player.UserId, coinsBadge3) then
				badgeService:AwardBadge(player.UserId, coinsBadge3)
			end
		end	
	end)
	
	player.CharacterAdded:Connect(function()
		local character = player.Character
		local At1 = Instance.new("Attachment", character:FindFirstChild("Head"))
        local At2 = Instance.new("Attachment", character:FindFirstChild("HumanoidRootPart"))
        At1.Name = "At1"
        At2.Name = "At2"
	end)

		
	exp.Changed:Connect(function(val)
		expDataStore:Set(val)
		if val >= (100 * (levels.Value + 1)) then
			levels.Value += 1
			exp.Value = 0
			game.ReplicatedStorage:WaitForChild("LevelUpGui"):FireClient(player)
			wait()
			Gems.Value += 50
		end
	end
	
	levels.Changed:Connect(function(val)	
		levelDataStore:Set(val)
	end)
	
	rebirths.Changed:Connect(function(val)	
		rebirthsDataStore:Set(val)
	end)
	
	noob.Changed:Connect(function(val)	
		noobDataStore:Set(val)
	end)
	
	gems.Changed:Connect(function(val)	
		gemsDataStore:Set(val)
	end)
end)

game.ReplicatedStorage.BuyItem.OnServerEvent:Connect(function(player, weight)
	if player.leaderstats.Coins.Value >= weight.Price.Value then
		player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - weight.Price.Value
		
		local newWeight = weight:Clone()
		newWeight.Parent = player.Backpack
	end
end)

game.ReplicatedStorage.AddExp.OnServerEvent:Connect(function(player)
	local expDataStore = DataStore2("Exp",player)

	player.leaderstats.Exp.Value += 20
	
	if MPS:UserOwnsGamePassAsync(player.UserId, gamepassID) == true then
		player.leaderstats.Exp.Value += 40
	end
end)

game.ReplicatedStorage.Rebirth.OnServerEvent:Connect(function(player)
	local GamepassID = 10646016
	
	if player.leaderstats.Coins.Value >= 10000 then
		player.leaderstats.Coins.Value = 0
		player.leaderstats.NoobPoints.Value = 0
		
		player.leaderstats.Rebirths.Value += 1
		
		if MPS:UserOwnsGamePassAsync(player.UserId, gamepassID) == true then
			player.leaderstats.Rebirths.Value += 2
		end
		
		game.ReplicatedStorage:WaitForChild("Rebirth"):FireClient(player)
	end
end)

Hi EmbatTheHybrid,

I am so sorry for sending that message on showing me the part of the script that I need to change. Thank you for replying to me I will test this out. If I have any other issues with this I will reply to you.

Thank you

Soggy_Bomb

1 Like

It’s fine! Sometimes we get impatient with our errrors that we just want to get it fixed already so we as kfor people to fix the script, but I figured it wouldn’t help you at all if I didn’t explain what you were doing wrong, so I also gave an explanation of what you were doing incorrectly. I hope it works out, and if it didn’t work, please reply with what’s wrong, it may be a slight typo I may’ve made if you get a syntax error

I have came across another issue once I know the answer to this I pretty sure I’ll be alright:

NOWAY

I am making the GUI say the players amount of Gems or any other type of currency

NO

This is for the gems though, which one mentions NoobPoints? It’s probably that you may need to do a WaitForChild to wait for NoobPoints to be become a thing

SO if you have something like

local noobpoints = player.leaderstats.NoobPoints

Change it to

local noobpoints = player.leaderstats:WaitForChild("NoobPoints")

It was working this is my last issue:

;-;

Sorry for my late response, change player to plr to match with your parameter