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

How to get/create Datastore tables? [ANSWERED]

Asked by
IXLKIDDO 110
9 years ago

Currently, I am trying to make a script for a global banned list. I am trying to add playerIds to a table and possibly retrieve these playerIds. So far I got the part down where I can match playerIds (raw data for them though) and the part where they get kicked. Other than that I need help. Can anyone lead me in the right direction (new to using DataStores and I don't understand the wiki well)?

0
You've already got the saving portion down and you're now trying to get the saved values...? Or do you need help with both saving and fetching? ImageLabel 1541 — 9y

1 answer

Log in to vote
1
Answered by
ImageLabel 1541 Moderation Voter
9 years ago

referencing or creating new data store name

local DataStore = game:GetService('DataStoreService'):GetDataStore('Name');
local Players = game:GetService('Players')

function to authenticate player ban status if true, banned, elseif false, not? :D

function RequestBanStatus(player)
    return DataStore:GetAsync(player.userId)
end

function to update playerId's data store depending on boolean argument

local SetBanState = function(playerId, boolean)
    DataStore:UpdateAsync(playerId ,function(state)
        if boolean == false then
            return false
        else
            return true
        end
    end)
end

calls RequestBanStatus function and kicks player if returned value true

Players.PlayerAdded:connect(function(player)
    if RequestBanStatus(player) then
        pcall(function()
            print(player,'banned')
        end)
    end
end)

You could also create a BindableEvent and connect it to the SetBanState function so that you can call it in your chat based administration scripts. You can also create a table within the script containing permanently banned userIds which you would of course add in the RequestBanStatus function in addition to the already existing check.

local DataStore = game:GetService('DataStoreService'):GetDataStore('Name');
local Players = game:GetService('Players')


local SetBanState = function(playerId, boolean)
    DataStore:UpdateAsync(playerId ,function(state)
        return boolean or state
    end)
end
function RequestBanStatus(player)
    return DataStore:GetAsync(player.userId) 
end

Players.PlayerAdded:connect(function(player)

    if RequestBanStatus(player) then
        pcall(function()
            warn('player, banned')
        end)
    end
end)
0
If you don't mind me asking. How would I possibly be able to get a playerid from a table (ie. IXLKIDDO returns this id, Imagelabel returns that id, Randomperson returns another id) when it's their name IXLKIDDO 110 — 9y
0
Do you mean getting any player's userId or fetching it from an already existing table? ImageLabel 1541 — 9y
0
Fetching it from an already existing table. What I've done is try and make a DataStore:SetASync but when I try and fetch people's playerId (when their name is inside of the table), it won't work. IXLKIDDO 110 — 9y
0
save their userIds as key instead of usernames, and then get their names when you fetch the userId ImageLabel 1541 — 9y
Ad

Answer this question