Ban Datastore won't work

Hello, I am making a ban data-store that uses tables…

Problem is, when I attempt to click to save a player to a data store, it won’t save, and as soon as I check the data store key, nothing was saved…

I have another separate panel of this, it works and saves, but when I copy the code to the other panel, it won’t work, even if the directories are correct and what not.

ERROR: “result.State is nil”

Datastore handler:

local DSS = game:GetService("DataStoreService")
local Key = DSS:GetDataStore("LyfeBan_1")
local Bans = {}

game.Players.PlayerAdded:Connect(function(plr)
	for i,v in pairs(Bans) do
		if plr.UserId == i then
			plr:Kick("\n\n == LYFE ADMIN SYSTEM == \n\n You have been terminated from Lyfe or possibly all Disruption Studio games. \n\n Reason: " .. tostring(v) .. " \n\n If you think this was a mistake, please contact a HR or higher to unban you! \n")
		end
	end
	
	local success, result = pcall(function()
		 return Key:GetAsync(plr.UserId)
	end)
	
	pcall(function()
	if success then
		if result.State == true then
			plr:Kick("\n\n == LYFE ADMIN SYSTEM == \n\n You have been terminated from Lyfe or possibly all Disruption Studio games. \n\n [Reason: " .. tostring(result.Reason) .. "] \n [Moderator: " .. tostring(result.Moderator) .. "] \n Time Executed: [" .. result.Date .. "] \n\n If you think this was a mistake, please contact a HR or higher to unban you! \n")
			end
		end
	end)
end)

Saving script:

script.Parent.OnServerEvent:Connect(function(plr, target, reason)
	local WL = require(script.Parent.Parent.Parent.Parent.Parent.Parent:WaitForChild("WL"))
	
	if plr:GetRankInGroup(5124833) >= WL.WLRole then
		game:GetService("DataStoreService"):GetDataStore("LyfeBan_1"):SetAsync(tonumber(game.Players:GetUserIdFromNameAsync(target)), {State = true, Reason = tostring(script.Parent.Parent.Parent.Parent.Parent:WaitForChild("Fields"):WaitForChild("Reason").Text), Moderator = tostring(plr.Name), Date = tostring(os.date("%c", os.time()))})
			for _, player in pairs(game.Players:GetPlayers()) do
				if player.Name == tostring(target) then
				player:Kick("\n\n == LYFE ADMIN SYSTEM == \n\n You have been terminated from Lyfe or possibly all Disruption Studio games. \n\n [Reason: " .. tostring(reason) .. "] \n [Moderator: " .. tostring(plr.Name) .. "] \n Time Executed: [" .. tostring(os.date("%c", os.time())) .. "] \n\n If you think this was a mistake, please contact a HR or higher to unban you! \n")
			end
		end
		game.ReplicatedStorage:WaitForChild("Broadcast"):FireAllClients(tostring(target) .. " was banned", Color3.fromRGB(255, 255, 0))
	end
end)

Seems like you never check to see if result actually exists after retrieving the DataStore for the specific player id scope. Perhaps try the following for the DataStore handler script:

local DSS = game:GetService("DataStoreService")
local Key = DSS:GetDataStore("LyfeBan_1")
local Bans = {}

game.Players.PlayerAdded:Connect(function(plr)
	for i,v in pairs(Bans) do
		if plr.UserId == i then
			plr:Kick("\n\n == LYFE ADMIN SYSTEM == \n\n You have been terminated from Lyfe or possibly all Disruption Studio games. \n\n Reason: " .. tostring(v) .. " \n\n If you think this was a mistake, please contact a HR or higher to unban you! \n")
		end
	end

	local success, result = pcall(function()
		return Key:GetAsync(plr.UserId)
	end)

	pcall(function()
		if success then
			if not result then return end
			if result.State == true then
				plr:Kick("\n\n == LYFE ADMIN SYSTEM == \n\n You have been terminated from Lyfe or possibly all Disruption Studio games. \n\n [Reason: " .. tostring(result.Reason) .. "] \n [Moderator: " .. tostring(result.Moderator) .. "] \n Time Executed: [" .. result.Date .. "] \n\n If you think this was a mistake, please contact a HR or higher to unban you! \n")
			end
		end
	end)
end)
1 Like

That does fix the errors, but for the ban button, it won’t set the ASync, and no errors print is the main problem…

problem:

image
(won’t even save the data)

script:

script.Parent.OnServerEvent:Connect(function(plr, target, reason)
	local WL = require(script.Parent.Parent.Parent.Parent.Parent.Parent:WaitForChild("WL"))
	
	if plr:GetRankInGroup(5124833) >= WL.WLRole then
		game:GetService("DataStoreService"):GetDataStore("LyfeBan_1"):SetAsync(tonumber(game.Players:GetUserIdFromNameAsync(target)), {State = true, Reason = tostring(script.Parent.Parent.Parent.Parent.Parent:WaitForChild("Fields"):WaitForChild("Reason").Text), Moderator = tostring(plr.Name), Date = tostring(os.date("%c", os.time()))})
			for _, player in pairs(game.Players:GetPlayers()) do
				if player.Name == tostring(target) then
				player:Kick("\n\n == LYFE ADMIN SYSTEM == \n\n You have been terminated from Lyfe or possibly all Disruption Studio games. \n\n [Reason: " .. tostring(reason) .. "] \n [Moderator: " .. tostring(plr.Name) .. "] \n Time Executed: [" .. tostring(os.date("%c", os.time())) .. "] \n\n If you think this was a mistake, please contact a HR or higher to unban you! \n")
			end
		end
		game.ReplicatedStorage:WaitForChild("Broadcast"):FireAllClients(tostring(target) .. " was banned", Color3.fromRGB(255, 255, 0))
	end
end)

no errors in console

Bumping, the fix is needed urgently.

Bumping one more time, fix is critically needed.

Solutions has been tried.