Skip to content

Commit

Permalink
fix: adjust DataStore connection
Browse files Browse the repository at this point in the history
  • Loading branch information
matyasjay committed Nov 6, 2024
1 parent 4073d40 commit 3ca1f6f
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/Configuration/RemoteConfig.luau
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
local Remote = {}

--[=[
@prop Version 0.2.2
@prop Version 0.2.4
@readonly
@within Remote
Expand All @@ -20,11 +20,11 @@ local Remote = {}
:::
]=]

Remote.Version = "0.2.2"
Remote.Version = "0.2.4"

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DataStore = game:GetService("DataStoreService")
local Store = DataStore:GetDataStore("CampingStats_0.2.2")
local Store = DataStore:GetDataStore(`CampingStats_{Remote.Version}`)
local AttributesConfig = require(ReplicatedStorage:WaitForChild("AttributesConfig"))
local StatisticsConfig = require(ReplicatedStorage:WaitForChild("StatisticsConfig"))
local Attributes = require(ReplicatedStorage.Variables:WaitForChild("Attributes"))
Expand Down Expand Up @@ -63,7 +63,7 @@ Remote.Statistics = StatisticsConfig.Keys
function Remote.Initialize(player)
player.CharacterAppearanceLoaded:Connect(function()
local data = Remote.GetRemote(player)
Statistics.Put(StatisticsConfig.Keys.TotalVisits, data[StatisticsConfig.Keys.TotalVisits].Value + 1)
Statistics.Put(StatisticsConfig.Keys.TotalVisits, data[StatisticsConfig.Keys.TotalVisits] + 1)
StatsGui.showStatsFrame(player)
Remote.PushRemote(player, data)
game.OnClose = Remote.Teardown(player, data)
Expand Down Expand Up @@ -94,21 +94,19 @@ function Remote.GetRemote(player)
end

function Remote.PushRemote(player, data)
local stored = {}
pcall(function()
Store:SetAsync(player.UserId, data)
for key in data do
stored[key] = data[key].Value
end
Store:SetAsync(player.UserId, stored)
end)
end

function Remote.Teardown(player, data)
return function()
local stored = {}
local statistics = Statistics.GetAll()
for key in data do
stored[key] = statistics[key].Value
end
pcall(function()
Store:SetAsync(player.UserId, stored)
end)
Remote.PushRemote(player, statistics)
end
end

Expand Down

0 comments on commit 3ca1f6f

Please sign in to comment.