SOLVED! Ban command not working. Using a DataStore editor plugin works but command doesn't?
Asked by
4 years ago Edited 4 years ago
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:
02 | local Players = game:GetService( "Players" ) |
06 | local DataStoreService = game:GetService( "DataStoreService" ) |
08 | local DataStore = DataStoreService:GetDataStore( "myDataStore" ) |
10 | local function onOwnerChatted(player, message) |
11 | if message:sub( 1 , ban:len()):lower() = = ban:lower() then |
12 | local name = message:sub(ban:len() + 1 ) |
13 | local playerToban = Players:FindFirstChild(name) |
15 | local success, eror = pcall ( function () |
16 | DataStore:SetAsync(player.UserId.. "-banned" , true ) |
19 | playerToban:Kick( "You have been banned by the owner." ) |
23 | game.ReplicatedStorage.Notifications:FireClient(player,name.. " is not a player!" ) |
29 | local function onPlayerAdded(player) |
30 | if player.UserId = = game.CreatorId and game.CreatorType = = Enum.CreatorType.User then |
31 | player.Chatted:Connect( function (...) |
32 | onOwnerChatted(player, ...) |
37 | for _, player in pairs (Players:GetPlayers()) do |
40 | Players.PlayerAdded:Connect(onPlayerAdded) |
02 | local DataStoreService = game:GetService( "DataStoreService" ) |
03 | local DataStore = DataStoreService:GetDataStore( "myDataStore" ) |
04 | game.Players.PlayerAdded:Connect( function (player) |
06 | banned = DataStore:GetAsync(player.UserId.. "-banned" ) |
07 | if banned = = true then |
08 | player:Kick( "You are banned from this game by the owner!" ) |
09 | print (player.Name.. " is banned." ) |
11 | print (player.Name.. " is not banned" ) |