Why is this DataStore ban script throwing an error?
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:
01 | local localdata = game:GetService( "DataStoreService" ):GetDataStore( "bans" ) |
04 | game.Players.PlayerAdded:Connect( function (plr) |
07 | plrdata = localdata:GetAsync(plr.UserId.. "-ban" ) |
10 | if plrdata ~ = nil then |
12 | if plrdata [ 'bankey' ] = = true then |
13 | plr:Kick( "You have been banned by the admin " ..plrdata [ 1 ] .. ", you may appeal if eligible." ) |
18 | local banInfo = { "none" , false } |
20 | localdata:SetAsync(plr.UserId.. "-ban" , banInfo) |
Script that sets the table:
01 | game.ReplicatedStorage.RemoteEvents.Ban.OnServerEvent:Connect( function (plr, userid) |
03 | local banInfo = { plr.Name, [ 'bankey' ] = true } |
05 | game:GetService( "DataStoreService" ):GetDataStore( "bans" ):SetAsync(userid.. "-ban" , banInfo) |
08 | if game.Players:GetPlayerByUserId(userid) then |
09 | game.Players:GetPlayerByUserId(userid):Kick( "You have been banned by the admin " ..plr.Name.. "." ) |