NOTE: This is activated by the PlayerRemoving event.
local ds = game:GetService("DataStoreService"):GetGlobalDataStore()
ptnow = pts.Value
hsnow = hs.Value
local asynccode = p.Name .. "pts"
local asynccode2 = p.Name .. "hs"
if not (ds:GetAsync(asynccode) or false) then
ds:SetAsync(asynccode, 0)
end
if not (ds:GetAsync(asynccode2) or false) then
ds:SetAsync(asynccode2, 0)
end
ds:SetAsync(asynccode, ptnow)
ds:SetAsync(asynccode2, hsnow)
Sometimes when I play online and leave the value of "points" gets saved, other times it does not. It's really weird, is it because there is an inefficieny in my script?
Also it doesn't save "hsnow" (highscore). Here is the script which loads these values, maybe this has the issue:
NOTE: This is activated by the player joining.
local asynccode = p.Name .. "pts"
local asynccode2 = p.Name .. "hs"
if not (ds:GetAsync(asynccode) or false) then
ds:SetAsync(asynccode, 0)
end
if not (ds:GetAsync(asynccode2) or false) then
ds:SetAsync(asynccode2, 0)
end
local stats = Instance.new("NumberValue", p)
stats.Name = "leaderstats"
local HighScore = Instance.new("NumberValue", stats)
HighScore.Name = "HighScore"
HighScore.Value = (ds:GetAsync(asynccode2))
print(ds:GetAsync(asynccode2))
local Score = Instance.new("NumberValue", stats)
Score.Name = "Points"
Score.Value = ds:GetAsync(asynccode)
PLEASE NOTE: These are snippits from my scripts. The rest is just checks and connecting the function. Also it saves both values in the server test > start player system. Weird, huh?
