Not saving bans | Datastore Help Needed

Hello, I’ve had an issue with my ban module in my command system.

DataStore Issue:
It does not save any bans that are made using the GUI.

Screenshots/Code:

Video

Admin Module

--Ban Player--
local function ban(player, value)
	local players = game:GetService('Players')
	local sus,erro = pcall(function()
		local Id = players:GetUserIdFromNameAsync(player)
	end)
	if sus then
		local Id = players:GetUserIdFromNameAsync(player)
		local msg = tostring(player)..' has been banned'
		ds:SetAsync(Id, {true, value})
		for i,plr in pairs(game.Players:GetChildren()) do
			if plr.Name == player.Name then
				plr:kick("\n ⛔️ | You have been permanently banned. \n \n Reason: " .. value)
			end
		end
		local color = Color3.fromRGB(255, 56, 88)
		game.ReplicatedStorage.ChatMsg:FireAllClients(msg, color)
		print(tostring(player).." has been banned")
	end
end

--Unban Player
local function unban(player)
	local players = game:GetService("Players")
	
	local sus,erro = pcall(function()
		local Id = players:GetUserIdFromNameAsync(player)
	end)
	if sus then
		local Id = players:GetUserIdFromNameAsync(player)
		ds:RemoveAsync(Id)
		print(tostring(player).." has been unbanned")
	end
end

Loader Module

local ds = game:GetService("DataStoreService"):GetDataStore("BanDataTest106")

game.Players.PlayerAdded:Connect(function(plr)

	local data = ds:GetAsync(plr.UserId)

	if data then
		if data[1] == true then
			plr:Kick("\n ⛔️ | You have been permanently banned. \n \n Reason: " .. data[2])
		end
	end
end)

Solutions I’ve tried:
Messing around with the code.
Looking on the dev forum.

Only thing I got is right here:

I don’t know if the player parameter is a Player object or a String. If it’s the player object then just adjust the code right here:

if that doesn’t work I suggest you rewrite the whole thing.

1 Like

Try this?

--Ban Player--
local function ban(player, value)
	local players = game:GetService('Players')
	local sus,erro = pcall(function()
		local Id = players:GetUserIdFromNameAsync(player)
                if Id then
		local Id = players:GetUserIdFromNameAsync(player)
		local msg = tostring(player)..' has been banned'
		ds:SetAsync(Id, {true, value})
			player:Kick("\n ⛔️ | You have been permanently banned. \n \n Reason: " .. value)
		end
		local color = Color3.fromRGB(255, 56, 88)
		game.ReplicatedStorage.ChatMsg:FireAllClients(msg, color)
		print(tostring(player).." has been banned")
	end
        end)
end

--Unban Player
local function unban(player)
	local players = game:GetService("Players")
	
	local sus,erro = pcall(function()
        local Id = players:GetUserIdFromNameAsync(player)
	if Id then
		ds:RemoveAsync(Id)
		print(tostring(player).." has been unbanned")
	end
        end)
end

The string was not properly a string value. I did tostring(value) to it and it worked!