-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.lua
More file actions
40 lines (32 loc) · 1.12 KB
/
helpers.lua
File metadata and controls
40 lines (32 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
-- Function to handle Roblox data serialization
local HttpService = game:GetService('HttpService')
local Helpers = {}
function Helpers.serializeData(data)
return HttpService:JSONEncode(data)
end
function Helpers.deserializeData(jsonString)
return HttpService:JSONDecode(jsonString)
end
function Helpers.saveDataToFile(fileName, data)
local serializedData = Helpers.serializeData(data)
local success, errorMessage = pcall(function()
local folder = game:GetService('ReplicatedStorage'):FindFirstChild('DataStore') or Instance.new('Folder', game.ReplicatedStorage)
folder.Name = 'DataStore'
local file = Instance.new('StringValue')
file.Name = fileName
file.Value = serializedData
file.Parent = folder
end)
return success, errorMessage
end
function Helpers.loadDataFromFile(fileName)
local folder = game:GetService('ReplicatedStorage'):FindFirstChild('DataStore')
if folder then
local file = folder:FindFirstChild(fileName)
if file then
return Helpers.deserializeData(file.Value)
end
end
return nil
end
return Helpers