You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? I want to remove keys from a dataStore
-
What is the issue? The keys are not being removed
-
What solutions have you tried so far? I’ve tried getting rid of the pcalls to see if there are any errors.
I’m trying to get rid of keys from a data store, but it won’t work. Here is the script that sets them:
local DataStoreService = game:GetService("DataStoreService")
local passStore = DataStoreService:GetDataStore("PassStore")
local Players = game:GetService("Players")
Players.PlayerRemoving:Connect(function(plr)
print("plr removing")
local statsFolder = plr:WaitForChild("StatsFolder")
local pass = statsFolder and statsFolder:FindFirstChild("Pass")
if pass.Value == true then
local success, errorMessage = pcall(function()
passStore:SetAsync(plr.UserId, "passed")
end)
if not success then
warn(errorMessage)
end
if success then
print(tostring(plr.UserId))
end
end
end)
Here is the script that removes them:
local commands = {}
local prefix = "/"
local DataStoreService = game:GetService("DataStoreService")
local passStore = DataStoreService:GetDataStore("PassStore")
commands.remove = function(sender,arguments)
if sender:GetRankInGroup(11635716) >= 254 then
local userId = tonumber(arguments[1])
local success, errorMessage = pcall(function()
passStore:RemoveAsync(userId)
end)
if not success then
warn(errorMessage)
end
end
end
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message,recipient)
local splitString = message:split(" ")
local slashCommand = splitString[1]
local command = slashCommand:split(prefix)
local commandName = command[2]
print(commandName)
if commands[commandName] then
local arguments = {}
for i = 2, #splitString, 1 do
table.insert(arguments,splitString[i])
end
commands[commandName] (player,arguments)
end
end)
end)
This could be a problem with the pass boolean value from the first script because if it is true when I leave, it will add my userId to the store again, but it defaults to false, and doesn’t save when it has been changed to true, so I don’t think that’s the issue. How can I fix this?