Not sure why you have this part of the code as it will just kick everyone in the server.
I just said that in the first post but yeah
bro i am new to the scripting how would i know
I just rewrote the script (if this also doesn’t work could you show the entire script?
It doesnt work it just says index nil with kick
its the entire script already and i just have a unban script too under it but you dont have to see that
Can you show us what is now printed (with the new script) sorry but as I said I’m on mobile
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.
arguments 2 is just userid of the player
Oh not the Name of the player? Ok
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!
dont worry i have another script when they join if they are on data then they are banned
OK then the code should work I think.
Just want to point out that this condition is never going to be check as you lower the string so there will be no upper case letter.
With this script you will kick every player in the game, that’s why you get kicked. Turn that into
local targetPlayerUserId = game.Players:GetUserIdFromNameAsync("PlayerYouWantToBanNameGoesHere")
if targetPlayerUserId then
for i, player in pairs(game.Players:GetPlayers()) do
if player.UserId == targetPlayerUserId then
player:Kick()
break --break out of the loop as the player has been found
end
end
--Add the player's id to a datastore so you can save the ban, doing this here is helpful because it will ban the player regardless of them being in the server meaning you can ban them even if they are offline
end
yeah but there was some scripting mistakes so i fixed them then it worked otherwise it gave me errors
What mistakes? I don’t see any going over it.
You have to use the kicked player’s name as a check for the kick. Right Now the only thing your script does is that it checks if you said args[1] aka ;ban and then kicks everyone. You want to check if args[2] aka the player name is valid (is in the server) then kick that player. You may also record that player’s userID in a datastore to kick them if they rejoin.
This is the solution. Right here.
Yeah or above (WinterLife)‘s
[Char Limit]
Please set
or
as the solution.