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

How can i make my datastore for bans work? Am i missing something?

Asked by 5 years ago
Edited 5 years ago

Just wanted to make a ban datastore today, and i feel like i'm missing something on the code. Seems to not work in roblox with api services enabled. <--- Problem

local DataStore = game:GetService("DataStoreService")
local ds1 = DataStore:GetDataStore("BanDataStore")

game.Players.PlayerAdded:Connect(function(player)
    local folder = Instance.new("Folder",player)
    folder.Name = "PlayerValues"

    local banvalue = Instance.new("BoolValue",folder)
    banvalue.Value = false
    banvalue.Name = "BanValue"

end)


        --SetAsync.Ban
    game.Players.PlayerRemoving:Connect(function(player)
    if player.PlayerValues.BanValue.Value == true then
        ds1:SetAsync(player.UserId, player.PlayerValues.BanValue.Value)


--BanCheck
ds1:GetAsync(player.UserId, player.PlayerValues.BanValue.Value)
        if player.PlayerValues.BanValue.Value == true then
            player:Kick("Banned.")
        end
        end
        end)
0
Funny that you say that, I am writing a ban system for my game using data stores. AlphaGamer150 101 — 5y
0
^ Good luck writing it mate. User#22722 20 — 5y
0
I know. AlphaGamer150 101 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
local DataStore = game:GetService("DataStoreService")
local ds1 = DataStore:GetDataStore("BanDataStore")

game.Players.PlayerAdded:Connect(function(player)
    local folder = Instance.new("Folder",player)
    folder.Name = "PlayerValues"

    local banvalue = Instance.new("BoolValue",folder)
    banvalue.Value = false
    banvalue.Name = "BanValue"

    ds1:GetAsync(player.UserId, player.PlayerValues.BanValue.Value)
        if player.PlayerValues.BanValue.Value == true then
            player:Kick("Banned.")
        end
end)

--SetAsync.Ban
game.Players.PlayerRemoving:Connect(function(player)
    ds1:SetAsync(player.UserId, player.PlayerValues.BanValue.Value)
end)
Ad

Answer this question