So, for context, I have a game where you mess around in a 2D sandbox environment, and I want users to be able to publicly upload creations to a public list.
The way how this datastore system currently works, is that the store has keys represented by the page, which means each page can have up to 10 creations max.
But one thing I would like to add is a liking/voting system where users can click on one of these creations and a like to the datastore.
I have already tried this, but there were issues with multiple people liking/unliking the creation which caused things like inaccurate numbers and negative numbers.
How should I go about doing this? And also will I have to worry about data loss to players being able to write to a same public datastore key?
local function LoadFeaturedCreationsData(Player, Page, Order) -- Get community creations
local LevelSaves
local Success, ErrorMessage = pcall(function()
local PageReversed = FeaturedPagesUsed() - Page + 1
if Order == 0 then
LevelSaves = CreationsStore:GetAsync(Page .. FeaturedCreationsKey)
else
LevelSaves = CreationsStore:GetAsync(PageReversed .. FeaturedCreationsKey)
end
if not LevelSaves then
LevelSaves = {}
end
for i, LevelInfo in pairs(LevelSaves) do
LevelInfo.TrueIndex = i
if Order == 1 then
LevelInfo.TruePage = PageReversed
else
LevelInfo.TruePage = Page
end
--LevelInfo.LikedByUser = CheckIfLiked(Player, LevelInfo.CreationId)
end
if LevelSaves and Order == 1 then -- Newest first
table.sort(LevelSaves, Pred)
elseif LevelSaves then
table.sort(LevelSaves, PredReversed)
end
end)
if Success then
print("Successfully loaded featured creations data")
return {Success = true, Data = LevelSaves}
else
warn("Failed to load featured creations data: " .. ErrorMessage)
return {Success = false, Data = "Failed to load data: " .. ErrorMessage}
end
end