You can write your topic however you want, but you need to answer these questions:
-
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 -
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)