--set core values and load data-----
local plr = game.Players:FindFirstChild(script.Parent.Name)
repeat wait() until plr
local datastore = game:GetService("DataStoreService")
local mydata = datastore:GetDataStore("mydata")
local value = script.Parent.Gems
local data
local success, fail = pcall(function()
data = mydata:GetAsync(plr.UserId.."Gems")
end)
if success then
value.Value = data
else
print("data load failed")
warn(fail)
end
----------------------------------
--save data--
local debounce = false
game.Players.PlayerRemoving:Connect(function(plr)
local success, fail = pcall(function()
mydata:SetAsync(plr.UserId.."Gems",value.Value)
end)
if success then
print("data saved")
script.Parent:Destroy()
else
print("an error has occured while saving")
warn(fail)
end
end)
local changedebounce = false
local char = plr.Character
char.Humanoid.Died:Connect(function()
if not changedebounce then
changedebounce = true
local success, fail = pcall(function()
mydata:SetAsync(plr.UserId.."Gems",value.Value)
end)
if success then
print("data saved")
script.Parent:Destroy()
else
print("an error has occured while saving")
warn(fail)
end
end
wait(2)
end)
-----------------
this is my datastore for saving gems but I ran into issues. one of them is that everyone keeps saving the same value, so if one person has 100 gems then another person who loads their data now has 100 gems. im not sure what is going on as it should be saving data with a player's playerID.
some help with this and any other issues would be GREATLY appreciated.
