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)?
How to get/create Datastore tables? [ANSWERED]
1 answer
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
SetBanStatefunction 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 theRequestBanStatusfunction 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)
4 comments
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
Do you mean getting any player's userId or fetching it from an already existing table?
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.
save their userIds as key instead of usernames, and then get their names when you fetch the userId
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
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?