DataStore not working

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to make a data store script that if you have 1000 exp you get 1 point

  2. What is the issue? Include screenshots / videos if possible!
    Sometimes when i am near the block you need to click the game literally crash and if i get 1 point and i get again 1000 exp it dont get more and when i publish the game dont working sometimes it gets Billions of points or exp or Millions of exp or points without doing nothing and when i publish the game and i enter i get randomly points or exp

	local dataStore = game:GetService("DataStoreService")

local myDataStore = dataStore:GetDataStore("myDataStore")

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	
	
	local points = Instance.new("IntValue", leaderstats)
	points.Name = "Points"
	
	local exp = Instance.new("IntValue", leaderstats)
	exp.Name = "Exp"
	
	
	
	--DataStore
	
	local UserId = player.UserId
	local Data --- Getting the data for using the variable later
	
	local ok, errorMessage = pcall(function()
		
		Data = myDataStore:GetAsync(UserId)
	end)
	
	
	if ok == true then
		print("Data Load")
		points.Value = Data
	else
		print("Error Loading Data")
		
		error(errorMessage)
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local UserId = player.UserId
	local ok, errorMessage = pcall(function()
		myDataStore:SetAsync(UserId, player.leaderstats.Points.Value)
		myDataStore:SetAsync(UserId, player.leaderstats.Exp.Value)
	end)
	
	if ok == true then
		print("Data Saved")
		
	else
		print("Error Saving Data")
		
	end
end)


local part = game.Workspace.Part
local clickDetector = part.ClickDetector

clickDetector.MouseClick:Connect(function(player)
	player.leaderstats.Exp.Value = player.leaderstats.Exp.Value+ 50
	while true do
		if player.leaderstats.Exp.Value == 1000 then
			player.leaderstats.Points.Value = player.leaderstats.Points
	end
		end
	end)

Add a yield inside that while true do loop.

wait() or task.wait() will suffice.

When i get 1000 exp it dont get points

player.leaderstats.Points.Value = player.leaderstats.Points

You need to change this line of code, I’ll let you figure it out.

The code gets like 1000 points and not repeating after getting 1000 exp

player.leaderstats.Points.Value = player.leaderstats.Points.Value + 1234

You weren’t adding any value.

while wait(3) do
if player.leaderstats.Exp.Value == 1000 then
player.leaderstats.Points.Value = player.leaderstats.Points.Value + 1

it gets more than 1 point

Because you have it inside of a while loop, remove the entire while loop if you only want the code to execute once.

after that like i get 2000 exp and not getting + 1 point

clickDetector.MouseClick:Connect(function(player)
	player.leaderstats.Exp.Value += 50
	if player.leaderstats.Exp.Value % 1000 == 0 then
		player.leaderstats.Points.Value += 1
	end
end)

If you want 1 point per 1,000 exp. Make sure exp can only go up in increments of 50.