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)
So when you are creating the table baninfo. You said local banInfo = {plr.Name, [‘bankey’] = true }
You don’t have to have brackets for that. Just say
local banInfo = {Name = plr.Name, banKey = true }