Help with permanently removing a key from a datastore

I am working on a game where players can write messages and others can see them. In case a message is inappropriate, I have added a report system and if I believe the message is inappropriate, I press a button and the code uses datastore:RemoveAsync().

  1. What do you want to achieve? Keep it simple and clear!

I want to permanently delete a key from a globaldatastore.

  1. What is the issue? Include screenshots / videos if possible!

I have deleted data from the key but key seems to still exist when i use datastore:ListKeysAsync()

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have looked at other forum pages and I can’t find an answer that fits my code.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

IMPORTANT INFORMATION:
rl = datastore for list of reports this code is okay
ds = datastore for each message posted. each player can only post one message so i am saving each message to the players userid as the key

Take a look at the code inside of the if statement that wonders if I think the player is innocent or if their message needs to be removed.

game.ReplicatedStorage.Events.Quotes.RateReport.OnServerInvoke = function(plr,reportedid,rating)
	local data

	local s, e = pcall(function()
		data = rl:GetAsync("List1")
	end)
	
	if s then
		if data then
			data = game:GetService("HttpService"):JSONDecode(data)
			
			local found
			local listnum = 1
			
			for i, v in pairs(data) do
				print(v["Id"],reportedid)
				if tonumber(v["Id"]) == tonumber(reportedid) then
					found = v
					listnum = i
				end
			end
			
			--print(found,listnum)
			
			
			if found then
				if rating == "Innocent" then
					print(data)
					table.remove(data,listnum)
					print(data)
					
					pcall(function()
						rl:SetAsync("List1",data)
					end)
				elseif rating == "Remove" then
					table.remove(data,listnum)
					
					local d
					
					local success, errormessage = pcall(function()
						d = ds:GetAsync(tonumber(reportedid))
					end)
					
					if success then
						if d then
							local s1, e1 = pcall(function()
								ds:RemoveAsync(tonumber(reportedid))
							end)
							
							if s1 then
								return true,"Successfully removed quote from report list and game data."
							else
								return false,"Successfully removed report off of list, but did not remove quote: "..e1
							end
						else
							return false,"There is no quote to remove."
						end
					else
						return false,"Successfully removed report off of list, but did not remove quote: "..errormessage
					end
				end
			else
				return false, "Quote not on report list."
			end
		else
			return false,"Could not load list to remove from."
		end
	else
		return false,e
	end
end

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

I Usually do this with This Plugin called “Datastore Editor” (not really sure does it even get deleted using that) , but I found this post that “should” work, atleast did a year ago Permanently Deleting Data Store Key
.

To start with, I hope you are using TextService:FilterStringAsync as part of moderation.

For your question, if you use the keys to display information or whatever, and you need the key to be empty so no one can see it, why not save the blocked players’ ids, then when showing the keys or whatever the use case is, just ignore them if they are in the list of banned ids.

I am using Chat:FilterStringForBroadcast() right now, but I just have the report system there just in case any bypassing happens

For the meantime, I think am going to make any deleted messages not get removed. Instead the message will be force edited to “[content deleted]”. I don’t know whether to call this a solution though.

If it is the solution, that might as well call it that.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.