The ban script doesn’t appear to be kicking the player and the ban handler doesn’t work?
ban script:
ban.OnServerEvent:Connect(function(player, playerToBan, reason)
if not table.find(ADMIN, player.UserId) then return end
playeruserID = getUserIdFromUsername(playerToBan)
if playeruserID == 1 then
print("Cannot Ban This User!")
return
else
local success, errormessage = pcall(function()
BanData:SetAsync(playeruserID, true, reason)
end)
if success then
print("yes")
if game.Players:FindFirstChild(player) then
player:Kick(reason)
else
return
end
end
end
end)
and the ban handler:
local manualbans = {}
local DataStore = game:GetService("DataStoreService")
local banData = DataStore:GetDataStore("banData")
game.Players.PlayerAdded:Connect(function(player)
local playerID = player.UserId
if manualbans[playerID] then
player:Kick("You have been banned from the game! Appeal in our disc server.")
end
local banned
local success, errormessage = pcall(function()
banned = banData:GetAsync(playerID)
end)
if banned == true then
player:Kick("You have been banned from the game! Appeal in our disc server.")
end
end)
I saw this post : Need help with ban script but couldn’t get anything out of it. I appreciate any help!
You should be checking if it successfully got the data. You should also be checking if there is any actual data and you should set default data if there isn’t
You can try and add the banned player’s ID into a table and then everytime he joins, The game tries to see if the player’s ID matches with the banned ID to actually kick him again.
Oh, apparently there’s another issue. You cannot send instances over remotes and you’ll have to use a string reference of the user’s username(not always consistent though). You can fire their UserId instead and use this API to get the player(to ban):
local playerToBan = Players:GetPlayerFromUserId(targetPlayerUserId)
if playerToBan then
playerToBan:Kick()
end
return
Huh, I did not know of that! Though even after applying that… It still doesn’t do anything?
ban.OnServerEvent:Connect(function(player, playerToBan, reason)
if not table.find(ADMIN, player.UserId) then return end
playeruserID = getUserIdFromUsername(playerToBan)
if playeruserID == 1 then
print("Cannot Ban This User!")
return
else
local success, errormessage = pcall(function()
BanData:SetAsync(playeruserID, true, reason)
end)
if success then
local playerToBan = Players:GetPlayerFromUserId(playeruserID)
if playerToBan.Parent then
playerToBan:Kick(reason)
else
return
end
end
end
end)
It’s supposed to input username, then it gets transformed into userid through useridfromnameasync and then sets the id to true and the player is kicked, ban handler kicks them again when they rejoin.
local cache = {}
function getUserIdFromUsername(name)
if cache[name] then return cache[name] end
local player = Players:FindFirstChild(name)
if player then
cache[name] = player.UserId
return player.UserId
end
local id
pcall(function ()
id = Players:GetUserIdFromNameAsync(name)
end)
cache[name] = id
return id
end
I still have no clue whatsoever that could be the problem. Maybe the client script isn’t working as intended? Try debugging the issue there by printing Target.Text.