Help with datastore for level system

Hello i made a level system for my game and i’m trying to save it with datastore. i’m trying to save the exp value and level value. and when i leave and rejoin, it jumps to like 5+ more levels from what i had before and exp decreases. nothing saves

the script:

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("drdatastore")
local DataStore2 = DataStoreService:GetDataStore("drdatastore2")
local Players = game:GetService("Players")

game.Players.PlayerAdded:Connect(function(Player)	
	local profilefolders = Instance.new("Folder",Player)
	profilefolders.Name = "Profilefolders"
	
	local playervalues = Instance.new("Folder",profilefolders)
	playervalues.Name = "playervalues"

	local plrlevel = Instance.new("IntValue", playervalues)
	plrlevel.Name = "plrlevel"
	plrlevel.Value = 1	

	local plrexp = Instance.new("IntValue", playervalues)
	plrexp.Name = "plrexp"
	
	local requiredexp = Instance.new("IntValue", playervalues)
	requiredexp.Name = "requiredexp"
	requiredexp.Value = plrlevel.Value * 70
	
	
	
	plrexp.Changed:Connect(function(newExp)
		if plrexp.Value >= requiredexp.Value then
			plrlevel.Value += 1
			plrexp.Value -= requiredexp.Value
			requiredexp.Value = plrlevel.Value * 70
		end
	end)
	

	local Data = DataStore:GetAsync(Player.UserId)
	if Data then
		plrlevel.Value = Data.plrlevel
		plrexp.Value = Data.plrexp
	end
end)

game.Players.PlayerRemoving:Connect(function(Player)
	DataStore:SetAsync(Player.UserId, {
		["plrlevel"] = Player.Profilefolders.playervalues.plrlevel.Value;
		["plrexp"] = Player.Profilefolders.playervalues.plrexp.Value;
	})
end)
3 Likes

I don’t see anything wrong. Maybe its another script doing it.

1 Like

Probably because you didn’t set a value for plrexp.

1 Like

I saw this comment and really looked into the script again and noticed that the data store is written well. the problem was me writing the level up system in the same data store script. thanks and i moved it into another script and works now.