Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Ban system but it don't save, help ?

Asked by 2 years ago

(sorry if i had a bad english)

So i tried to make a "userdata" the money work fine but the ban no

Script :

local V = script.Parent.Value

local Save = true

if V == true then

    local DS = game:GetService("DataStoreService")

    local Data = DS:GetDataStore("UserData")

    game.Players.PlayerAdded:connect(function(P)


        local UserData = Instance.new("Folder", P)  
        UserData.Name = "UserData"

        local Leader = Instance.new("Folder", P)
        Leader.Name = "leaderstats"

        local Money = Instance.new("IntValue", Leader)
        Money.Name = "Money"
        if Save == true then
        Money.Value = Data:GetAsync(P.UserId) or 25
        else
        Money.Value = 25        
        end

        local Banned = Instance.new("BoolValue", UserData)
        Banned.Name = "Banned"
        Banned.Value = Data:GetAsync(P.UserId) or false

        if Banned.Value = true then
            P:Kick()
        end

        Data:SetAsync(P.UserId, Money.Value, Banned)

        Money.Changed:connect(function()
            Data:SetAsync(P.UserId, Money.Value)
        end)

        Banned.Changed:connect(function()
            Data:SetAsync(P.UserId, Banned.Value)
        end)

    end)


    game.Players.PlayerRemoving:connect(function(P)
        Data:SetAsync(P.UserId, P.leaderstats.Money.Value , P.UserData.Banned)
    end)

end

1 answer

Log in to vote
0
Answered by
sad_eyez 162
2 years ago
Edited 2 years ago

You could have a dictionary of preset banned players, and also save a table when you ban a player, I will post an examples of how I do my DataStore.

I use a MainModule as sort of an API so I don't have to worry about editing it to much, and I can use this same system in all my games, but this is how you would sort save a table of banned players, you would just have to script it a bit differently, I mainly use this one for stats.

Here is the MainModule Script:

local module = {}




function module.save(plr, stats, name, folderName)


    local dataService = game:GetService("DataStoreService"):GetDataStore(name)
    local leaderstats = plr:WaitForChild(folderName)

    local key = plr.UserId.. "-key"
    local values = {}
        for index,value in pairs(stats) do
            values[tostring(index)] = leaderstats[tostring(index)].Value
        end
    dataService:SetAsync(key, values)
end

function module.load(plr, stats, name, folderName)

    local dataService = game:GetService("DataStoreService"):GetDataStore(name)
    local leaderstats = plr:WaitForChild(folderName)

    local key = plr.UserId.. "-key"

    local savedValues = dataService:GetAsync(key)

    if savedValues then
        for index, value in pairs(savedValues) do
            leaderstats[tostring(index)].Value = value
        end
    else
        local values = {}
        for index,value in pairs(stats) do
            values[tostring(index)] = leaderstats[tostring(index)].Value
        end
        dataService:SetAsync(key, values)
    end

end

function module.insertstats(plr, stats, folderName, groupId, groupRank)

    local key = plr.UserId.. "-key"

    local leaderstats = Instance.new("Folder", plr)
    leaderstats.Name = folderName

    for index, value in pairs(stats) do
        local newValue = Instance.new("NumberValue", leaderstats)
        newValue.Name = tostring(index)
        newValue.Value = value
    end

    if (groupRank == true) then
        local rank = Instance.new("StringValue", leaderstats)
        rank.Name = "Rank"
        rank.Value = plr:GetRoleInGroup(groupId)
    end
end



return module
Ad

Answer this question