Temporary Ban Help

I’m attempting to make a time ban that uses DataStores and os.time(). I originally found this code from another post, so I decided to test it out and expand with it. However, I came across this error when I tried testing it out for myself.

I came across an error that stated: Argument 1 missing or nil this leads to line 15, which is TempBanStore:SetAsync(tonumber(Player.UserId), {BanStartTime = os.time(), BanTime = Times.OneDayBan})

Code:

local DataStoreService = game:GetService("DataStoreService")
local TempBanStore = DataStoreService:GetDataStore("TempBanStore",1)

local Times = {
	OneDayBan = 86400, -- One day ban in seconds
	ThreeDayBan = 259200, -- Three day ban in seconds
	FiveDayBan = 432000, -- Five day ban in seconds
	PermBan = 1,870,329,440 -- Perm ban in seconds (date is set to 2050)
}


game.ReplicatedStorage.RequestBan.OnServerEvent:Connect(function(Administrator, Player, Reason, BanTime)
	if Administrator:GetRankInGroup(2995276) >= 19 then -- Checks if the player is over the rank "Developer"
		if BanTime == "OneDay" then
			TempBanStore:SetAsync(tonumber(Player.UserId), {BanStartTime = os.time(), BanTime = Times.OneDayBan})
		end
	elseif BanTime == "ThreeDay" then
		if Player:GetRankInGroup(2995276) < 19 then -- Checks if the player is under the rank "Developer"
			local NewPlayer = game.Players:GetPlayerByUserId(Player.Name)
			TempBanStore:SetAsync(tonumber(Player.UserId), {BanStartTime = os.time(), BanTime = Times.ThreeDayBan})
		end
	elseif BanTime == "FiveDay" then
		if Player:GetRankInGroup(2995276) < 19 then -- Checks if the player is under the rank "Developer"
			TempBanStore:SetAsync(tostring(Player.UserId), {BanStartTime = os.time(), BanTime = Times.FiveDayBan})
		end
	elseif BanTime == "PERM" then
		if Player:GetRankInGroup(2995276) < 19 then -- Checks if the player is under the rank "Developer"
			TempBanStore:SetAsync(tostring(Player.UserId), {BanStartTime = os.time(), BanTime = Times.PermBan})
		end
	else
		Administrator:Kick("\nDon't exploit!\n") -- Kicks the player if they don't have the required group rank
	end
end)

game.Players.PlayerAdded:Connect(function(Player)
	local Success, Result = pcall(function()
		return TempBanStore:GetAsync(tostring(Player.UserId),"TempBan")
	end)
	if Success then
		if Result then
			if Result.BanStartTime + Result.BanTime > os.time() then
				-- No ban set for this user
			else
				Player:Kick("You are temp-banned")
			end
		end
	end
end)
1 Like

It means that the first argument of your function call is nil. In this case tonumber(Player.UserId).

1 Like

By the way, you should replace player and adminstrator. Players Applies to all the players that do this, only effects them. Move players to the first parameter and adminstrator to the second parameter.

Also, I have no idea why you even added adminstrators imo. You added for the first if statement, for adminstrators, but then all your “elseif” was just regular players. You have to specify those players on the local script.

1 Like