-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayerInventoryHandler.lua
More file actions
53 lines (37 loc) · 1007 Bytes
/
PlayerInventoryHandler.lua
File metadata and controls
53 lines (37 loc) · 1007 Bytes
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
41
42
43
44
45
46
47
48
49
50
51
52
53
local PlayerInventoryHandler = {}
local DataStoreService = game:GetService("DataStoreService")
local playerStore = DataStoreService:GetDataStore("PlayerInventory")
local Players = game:GetService("Players")
PlayerInventoryHandler.InventoryEnum = {
Sword = 0,
Gun = 1,
}
function PlayerInventoryHandler.Init(plrId)
local success, data = pcall(function()
print("found player")
return playerStore:GetAsync(plrId)
end)
if data == nil then
local created, error = pcall(function()
playerStore:SetAsync(plrId, {})
end)
if not created then
print(error)
end
end
end
function PlayerInventoryHandler.Read(plrId)
local success, data = pcall(function()
return playerStore:GetAsync(plrId)
end)
return data
end
function PlayerInventoryHandler.Write(plrId, data)
local created, error = pcall(function()
playerStore:SetAsync(plrId, data)
end)
if not created then
print(error)
end
end
return PlayerInventoryHandler