Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

SOLVED! Ban command not working. Using a DataStore editor plugin works but command doesn't?

Asked by 3 years ago
Edited 3 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:

            --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)
0
If it's not working, then it should be printing the "eror" message? If it does print it, do you mind posting it alongside your code? killerbrenden 1537 — 3y
0
It does not print the error message. TheWaildug 55 — 3y
0
I rewrote the code and now it works TheWaildug 55 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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

Ad

Answer this question