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

Are you able to make a ban script using datastore and remote events?

Asked by 6 years ago
local remote1 = game:GetService("ReplicatedStorage").Remotes.DataGiver
local remote2 = game:GetService("ReplicatedStorage").Remotes.KICK
local remote3 = game:GetService("ReplicatedStorage").Remotes.BAN
local ifbanned = game:GetService("DataStoreService"):GetDataStore("banned_false_true")
local admins = {
    'xXKillerMurderarXx';
    'dimondguy18_V2'
    }

remote3.OnServerEvent:connect(function(plr, name)
    for i, AM in ipairs(admins) do
        if plr.Name == AM then
            if name == AM then
                warn("You cant ban yourself! [ Though you can kick your self :d ]")
            else
                local player = game:GetService("Players"):FindFirstChild(name)
                if player then
                    local ID = game:GetService("Players")[player.Name].UserId
                    ifbanned:SetAsync(ID, 1)
                    wait()
                    print("SetAsync")       
                    wait(0.5)
                    player:Kick("Banned from the game!")
                end
            end
        end
    end
end)

remote2.OnServerEvent:connect(function(plr, name)
    for i, AM in ipairs(admins) do
        if plr.Name == AM then
            local player = game:GetService("Players"):FindFirstChild(name)
            if player then
                player:Kick("You have been kicked from the game by the administrators")
            end
        else
            if plr.Name == "dimondguy18_V2" then
                warn("Error : System attempted to ban admin")
            else
                local ID = game:GetService("Players")[plr.Name].UserId
                ifbanned:SetAsync(ID, 1)
                plr:Kick("You are banned from the game [ Exploiting ]")
            end
        end
    end
end)

game.Players.PlayerAdded:connect(function(plr)
    local r = ifbanned:GetAsync(plr.Name)
    print(r)

    wait(1)
    print(r)
    if r == 1 then
        if plr.Name == "xXKillerMurderarXx" then
            print("XD")
        else
            plr:Kick("You are banned from this game")
        end
        if plr.Name == "dimondguy18_V2" then
            print("XD")
        else
            plr:Kick("You are banned from this game")
        end
    end
end)

remote1.OnServerEvent:connect(function(plr, code)
    if code == "A-AaAAa_eaE_aeA_EAAa-EA_E_ae_AE-eeE_A_a-A_aea-Eae-eA_EAE_aeee_Aa-Eaea-eAe_" then
        local function short(name)
            local returned = {}
            for i,v in pairs(game.Players:GetPlayers()) do
                if v.Name:sub(1,name:len()):lower() == name:lower() then
                    table.insert(returned,v)
                end
            end
            return returned
        end

        plr.Chatted:connect(function(msg)
            for i, AM in ipairs(admins) do
                if plr.Name == AM then
                    if string.sub(msg,1,5):lower() == "kick/" then
                        local player = short(string.sub(msg,6))
                        if #player == 1 then
                            local player = player[1]
                            player:Kick("Kicked")
                        end
                    end
                end
            end
        end)

        for i, AM in ipairs(admins) do
            if plr.Name == AM then
                local ad = game:GetService("ReplicatedStorage").AdminGUI
                local ad2 = ad:Clone()
                local plrgu = plr:FindFirstChild("PlayerGui")
                print("Cloning...")
                if plrgu then
                    print("Cloned")
                    ad2.Parent = plrgu
                    wait()
                    ad2:FindFirstChild("Main").Disabled = false
                end
            end
        end
    end
end)

Since the game is filtering enabled, I use remote events to do this.

Every time I ban someone, they get kicked from the game with a message saying "You are banned from this game" but the data does not get saved for some reason. Studio works perfectly with the script, but the actual game it self does not. ( This script is placed in server scripts service )

Is there a way to fix this or is there supposed to be a different method for this??

0
can u accept :p cabbler 1942 — 6y

1 answer

Log in to vote
1
Answered by
cabbler 1942 Moderation Voter
6 years ago

You SetAsync player.UserId, but then GetAsync with player.Name onPlayerAdded. Obvious issues.

UserId should be used for all internal data. Never names; users can change their names. This isn't only for admin scripts either. be consistent

0
ohhhhhh lol silly meee xXKillerMurderarXx 59 — 6y
Ad

Answer this question