Module MemoryHandler.lua
-- MemoryHandler.lua
local MemoryStoreService = game:GetService("MemoryStoreService")
local module = {}
module.__index = module
function module.new(name: string, expiration: number)
local self = setmetatable({}, module)
self.expiration = expiration or 3600 -- 1h mặc định
self.store = MemoryStoreService:GetSortedMap(name)
return self
end
-- Lưu dữ liệu vào Map
function module:Set(key: string, value, ttl: number)
local success, err = pcall(function()
self.store:SetAsync(key, value, ttl or self.expiration)
end)
return success
end
-- Lấy dữ liệu từ Map
function module:Get(key: string): Variant
local success, result = pcall(function()
return self.store:GetAsync(key)
end)
if success then return result end
return nil
end
-- Cập nhật dữ liệu (giữ giá trị cũ để chỉnh)
function module:Update(key: string, callback: (Variant) -> Variant, ttl: number): Variant
local success, result = pcall(function()
return self.store:UpdateAsync(key, function(v: Variant)
return callback(v)
end, ttl or self.expiration)
end)
if success then return result end
return nil
end
-- Xoá key trong Map
function module:Remove(key: string): boolean
local success, _ = pcall(function()
self.store:RemoveAsync(key)
end)
return success
end
return module
When I run the below script on the server, it always throws the error “MemoryStoreService: InternalError: Internal Error. API: SortedMap.Set, Data Structure: UnknownMemoryStoreSortedMap.”
This error only shows when i use roblox studio but i still cant fix it
local MemoryHandler = require(ServerScriptService.Modules.MemoryHandler)
local MemoryStore = MemoryHandler.new("PlayerStages")
Players.PlayerRemoving:Connect(function(player)
MemoryStore:Set(player.UserId, 1)
end)
