Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Is there a better way to store likes and dislikes than OrderedDataStore?

So I made a system that allows one to like or dislike a part of the game (an obby) and it works just fine. The only problem is, it uses Pages to get the likes and dislikes. The max size for a page is 100, which means only 100 likes/dislikes can be recorded. I feel like if my game gets popular there will be way more than 100 likes or dislikes, so what do I do? Thanks for any help!

EDIT: I forgot to mention. It updates every 2.5 seconds (So to not overrun the datastores) but I am good with that :)

Script:

local Datastore = game:GetService("DataStoreService")
local ThumbsUpStore = Datastore:GetOrderedDataStore(script.Parent.Parent.Name.."-ThumbsUp")
local ThumbsDownStore = Datastore:GetOrderedDataStore(script.Parent.Parent.Name.."-ThumbsDown")

local ThumbsUp = script.Parent.ThumbsUp.ClickDetector
local ThumbsDown = script.Parent.ThumbsDown.ClickDetector

Likes = 0
Dislikes = 0

ThumbsUp.MouseClick:Connect(function(player)
	ThumbsUpStore:SetAsync(player.Name,1)
	ThumbsDownStore:SetAsync(player.Name,0)
	print("Thumbs Up")

end)

ThumbsDown.MouseClick:Connect(function(player)
	ThumbsUpStore:SetAsync(player.Name,0)
	ThumbsDownStore:SetAsync(player.Name,1)
	print("Thumbs Down")
	
end)

while true do
	wait(2.5)
	local Size = 100
	local PagesUp = ThumbsUpStore:GetSortedAsync(true,Size)
	local PagesDown = ThumbsDownStore:GetSortedAsync(true,Size)
	local PageUp = PagesUp:GetCurrentPage()
	local PageDown = PagesDown:GetCurrentPage()
	Likes = 0
	Dislikes = 0
	
	for i, data in ipairs(PageUp) do
		if data.value == 1 then
			Likes = Likes + 1
		end
	end
	for i, data in ipairs(PageDown) do
		if data.value == 1 then
			Dislikes = Dislikes + 1
		end
	end
	ThumbsUp.Parent.SurfaceGui.TextLabel.Text = tostring(Likes)
	ThumbsDown.Parent.SurfaceGui.TextLabel.Text = tostring(Dislikes)
end

3 comments

0

I haven't worked with roblox's ordered data stores before, but is there a reason why you can't use multiple pages?

0

Also, why does it have to be an ordered datastore? Can't you use a regular datastore and also save it with the time the button was pressed if you want to save chronologically?

0

Oh god I am so stupid. Thank you so much!

1 answer

I have figured it out myself! Thanks for those who tried to help!

This discussion is preserved as it was. New answers, comments, and votes are closed.