I am experimenting with a simple ban system. I am trying to save the admin name and a true/false value that says whether the player is banned or not. To do this, I am saving a table and it is not going so well. It throws this error when I try to index plrdata: ServerScriptService.BanWatch:12: attempt to index local 'plrdata' (a boolean value). I am not sure why it is doing this.
Script that watches for banned players to join:
local localdata = game:GetService("DataStoreService"):GetDataStore("bans")
game.Players.PlayerAdded:Connect(function(plr)
local plrdata
pcall(function()
plrdata = localdata:GetAsync(plr.UserId.."-ban")
end)
if plrdata ~= nil then
if plrdata['bankey'] == true then
plr:Kick("You have been banned by the admin "..plrdata[1]..", you may appeal if eligible.")
end
else
local banInfo = {"none", false}
localdata:SetAsync(plr.UserId.."-ban", banInfo)
end
end)
Script that sets the table:
game.ReplicatedStorage.RemoteEvents.Ban.OnServerEvent:Connect(function(plr, userid)
local banInfo = {plr.Name, ['bankey'] = true}
game:GetService("DataStoreService"):GetDataStore("bans"):SetAsync(userid.."-ban", banInfo)
if game.Players:GetPlayerByUserId(userid) then
game.Players:GetPlayerByUserId(userid):Kick("You have been banned by the admin "..plr.Name..".")
end
end)

4 comments
Have you tried this in an actual game and not studio? Datastores in studio dont work at the moment
@EnzTDZ_YT i dont think it would be the studios fault if the error is about the misinterpretation of "plrdata" being a bool
Utilize pcall's return values (success, error?) to determine if plrdata was unable to be retrieved. If success is false, return false to the function. Otherwise, continue. That's the purpose of pcall.
@Fifkee Yeah thats true here is some example : if success then print("Data successfully saved")