DataStore Duplicating Levels

Hi,

So i made this DataStore a while ago, and when i cam back, its duplicating the Levels, how can i fix this?

Example: if im at Level 3, i leave the game, but when i come back, its now Level 50 - 350

Im either overlooking something or my script is broken

Script
local Data = game:GetService("DataStoreService"):GetDataStore("Data")
local Players = game:GetService("Players")



Players.PlayerAdded:Connect(function(Plr)
	local DataKey = "Player_"..Plr.UserId
	local ls,ss = Instance.new("Folder", Plr), Instance.new("Folder", Plr)
	ls.Name = "leaderstats"
	ss.Name = "Saved_Stats"

	local Cash = Instance.new("IntValue", ss)
	Cash.Name = "Cash"
	Cash.Value = Data:GetAsync(DataKey, Cash.Value) or 500
	
	local Level = Instance.new("IntValue", ls)
	Level.Name = "Level"
	Level.Value = Data:GetAsync(DataKey, Level.Value) or 1

	local EXP = Instance.new("IntValue", ss)
	EXP.Name = "EXP"
	EXP.Value = Data:GetAsync(DataKey, EXP.Value) or 0


	local REXP = Instance.new("IntValue", ss)
	REXP.Name = "REXP"
	REXP.Value = Level.Value*250



	EXP:GetPropertyChangedSignal("Value"):Connect(function()
		if EXP.Value >= REXP.Value then
			EXP.Value -= REXP.Value
			Level.Value += 1
			REXP.Value = Level.Value*250
			Data:SetAsync(DataKey, Level.Value)
			
		end
		Data:SetAsync(DataKey, EXP.Value)
	end)
	
	Players.PlayerRemoving:Connect(function()
		Data:SetAsync(DataKey, Cash.Value)
		Data:SetAsync(DataKey, EXP.Value)
		
	end)
	
	
end)

(Note this is old, it worked before but now it doesnt work right)

You are replacing the data to the exp’s value, this probably why.

Nevermind, i found the issue,

Thanks

That wasnt the Case, somehow the Levels Value was Changing to the Cash Value

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