I remade the kick script on https://developer.roblox.com/en-us/api-reference/function/Player/Kick into a ban script. I used DataStores to store the banned player. When I use a DataStore Editor, I can add the person. But when I use the command, it doesn't work. Here is my script:
--ban command local Players = game:GetService("Players") local ban = "/ban" local DataStoreService = game:GetService("DataStoreService") local DataStore = DataStoreService:GetDataStore("myDataStore") local function onOwnerChatted(player, message) if message:sub(1, ban:len()):lower() == ban:lower() then local name = message:sub(ban:len() + 1) local playerToban = Players:FindFirstChild(name) if playerToban then local success, eror = pcall(function() DataStore:SetAsync(player.UserId.."-banned",true) end) if success then playerToban:Kick("You have been banned by the owner.") print("Banned") else warn(eror) game.ReplicatedStorage.Notifications:FireClient(player,name.." is not a player!") end end end end local function onPlayerAdded(player) if player.UserId == game.CreatorId and game.CreatorType == Enum.CreatorType.User then player.Chatted:Connect(function (...) onOwnerChatted(player, ...) end) end end for _, player in pairs(Players:GetPlayers()) do onPlayerAdded(player) end Players.PlayerAdded:Connect(onPlayerAdded)
--checking for banned person on different script when they join (this works) local DataStoreService = game:GetService("DataStoreService") local DataStore = DataStoreService:GetDataStore("myDataStore") game.Players.PlayerAdded:Connect(function(player) local banned banned = DataStore:GetAsync(player.UserId.."-banned") if banned == true then player:Kick("You are banned from this game by the owner!") print(player.Name.." is banned.") else print(player.Name.." is not banned") end end)
I followed AlvinBlox's video on making an admin command format and put my code into there and now it works! https://www.youtube.com/watch?v=ZJE_xTzOdLs.
Admin script can be found here: roblox.com/library/5052993019/e