hello first welcome to my thread i need help with kicking the player so i can actually ban them but instead it kicks me instead of the targeted player when i use the command
local Admins = {1172975825,"BerkayTheCamper1"}
local Prefix = ";"
local BanData = {}
function checkAdmin(player)
for i,v in ipairs(Admins) do
if type(v) == 'number' and player.UserId == v then
return true
elseif type(v) == 'string' and player.Name == v then
return true
end
end
end
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
local loweredString = string.lower(msg)
local args = string.split(loweredString," ")
if args[1] == Prefix.."ban" or args[1] == Prefix.."Ban" then
for _,player in pairs(game:GetService("Players"):GetPlayers()) do game:GetService("DataStoreService"):GetDataStore("BanStore"):SetAsync(args[2], BanData)
player:Kick("Banned")
end
end
end
end)
end)
also i am new to scripting so no hate also i didnt find any threads about it
local Admins = {1172975825,"BerkayTheCamper1"}
local Prefix = ";"
local BanData = {}
function checkAdmin(player)
for i,v in ipairs(Admins) do
if type(v) == 'number' and player.UserId == v then
return true
elseif type(v) == 'string' and player.Name == v then
return true
end
end
end
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
local loweredString = string.lower(msg)
local args = string.split(loweredString," ")
if args[1] == Prefix.."ban" or args[1] == Prefix.."Ban" then
game:GetService("DataStoreService"):GetDataStore("BanStore"):SetAsync(args[2])
print(args[2])
game.Players:FindFirstChild(args[2]):Kick("Banned")
end
end
end)
end)
I just don’t know if this is exactly working because I‘m not at home and I only have my Phone to write this.
The issue with the code you sent is that you are trying to find the player via the args 2 but the args 2 you are finding are all lowercase due to the string.lower(msg) and the user might have caps in there name.
Here is an edited version of your code. Should work.
I edited it to make it find the player in the correct way and also due to the way datastores work you need have it in a pcall function because sometimes it might not save to the datastore so we only want the user to be kicked if the user was successfully banned from the game (saved to the datastore)
local Admins = {1172975825,"BerkayTheCamper1"}
local Prefix = ";"
local BanData = {}
function checkAdmin(player)
for i,v in ipairs(Admins) do
if type(v) == 'number' and player.UserId == v then
return true
elseif type(v) == 'string' and player.Name == v then
return true
end
end
end
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
local loweredString = string.lower(msg)
local args = string.split(loweredString," ")
local Normal = string.split(msg, " ")
if args[1] == Prefix.."ban" then
game:GetService("DataStoreService"):GetDataStore("BanStore"):SetAsync(args[2], BanData)
local success, errorMessage = pcall(function()
game:GetService("DataStoreService"):GetDataStore("BanStore"):SetAsync(args[2], BanData)
end)
if success then
if game:GetService("Players"):GetPlayerByUserId(args[2]) then
game:GetService("Players"):GetPlayerByUserId(args[2]):Kick("Banned")
end
else
print(errorMessage)
end
end
end)
end)
You then also need to deal with the kick system when someone joins and they are banned!