Hi there guys,
I’m currently creating a script to create a store for the player using OOP and it’s been very efficient, especially in the datastore part, but I found myself in a slightly controversial situation.
I’m not able to find a viable way to send data from the server to the client efficiently - by that I mean without using remote events because they would probably be called several times.
Server:
local StoreManager = require(game.ReplicatedStorage:WaitForChild("StoreManipulationSystem"):WaitForChild("Modules"):WaitForChild("StoreModule"))
local ItemManipulation = game.ReplicatedStorage:WaitForChild("StoreManipulationSystem"):WaitForChild("Functions"):WaitForChild("ItemManipulation")
local Players = game:GetService("Players")
local Stores = {}
Players.PlayerAdded:Connect(function(player)
local store = StoreManager.new(player)
Stores[player.UserId] = store
print("print stores",Stores)
end)
Players.PlayerRemoving:Connect(function(player)
if Stores[player.UserId] then
Stores[player.UserId]:SaveData()
Stores[player.UserId] = nil
end
end)
-- (...)
Module stuff:
local StoreManager = {}
StoreManager.__index = StoreManager
local DataStoreService = game:GetService("DataStoreService")
local StoreData = DataStoreService:GetDataStore("PlayerStoreData")
function StoreManager.new(player)
local self = setmetatable({}, StoreManager)
self.Player = player
self.StorageCapacity = 50
self.Items = {}
local success, data = pcall(function()
return StoreData:GetAsync(player.UserId)
end)
if success and data then
self.StorageCapacity = data.StorageCapacity or 50
self.Items = data.Items or {}
end
return self
end
return StoreManager
-- (...)
some things like the current storage capacity and the items I need to display in a bar that is obviously on the client, but I can’t access it any other way other than through remote events or functions, which ends up weighing down my game because these requests are made almost every time.
any ideas?