Hi,
Recently, I was to make a ban system by using DataStore, but when I check if the player has the table that contains if the player banned or not and the reason for the ban, it returns an error tells me that it doesn’t exist.
Error1:
Another weird thing, when I try to unban a player that already banned and has the table, it gives me the same error that tells me that there is nothing called “banned”
Error2:
CODE:
local repStorage = game:GetService("ReplicatedStorage")
local dataStoreService = game:GetService("DataStoreService")
local players = game:GetService("Players")
local banRemote = repStorage:WaitForChild("BanRemote")
local banRemoteReturn = repStorage:WaitForChild("BanRemoteReturn")
local banList = dataStoreService:GetDataStore("BanList")
local function kickPlayer(plyr, msg)
if players:FindFirstChild(plyr) then
print(plyr)
print(plyr.ClassName)
players[plyr]:Kick(msg)
end
end
players.PlayerAdded:Connect(function(plr)
local playerId = plr.UserId
local plyerStatues
local success, errorMassage = pcall(function()
plyerStatues = banList:GetAsync(playerId)
end)
if plyerStatues.banned then
print(plyerStatues.banned, plyerStatues.reason.."reason")
if plyerStatues.banned == true then --Error1
plr:Kick(plyerStatues.reason)
end
end
end)
banRemote.OnServerEvent:Connect(function(plr, intendedPlr, command, massage, bantime)
print(command)
print(typeof(command))
if command == "Ban" then
print("Called Ban")
local playerId = players:GetUserIdFromNameAsync(intendedPlr)
local setBan
local plyerStatues
local alreadyBanned
local success, errorMassage = pcall(function()
plyerStatues = banList:GetAsync(playerId)
alreadyBanned = plyerStatues.banned
end)
if alreadyBanned == true then
banRemoteReturn:FireClient(plr, command,"Already Banned")
return
end
local good, errorMassage = pcall(function()
setBan = banList:SetAsync(playerId, {banned = true; reason = massage;})
end)
kickPlayer(intendedPlr, "You have been banned for "..massage)
banRemoteReturn:FireClient(plr, command,"Successfully Banned")
return
end
if command == "Kick" then
print("Called Kick")
kickPlayer(intendedPlr, "You were kicked for "..massage)
banRemoteReturn:FireClient(plr, command,"Successfully Kicked")
return
end
if command == "Unban" then
print("Called Unban")
local playerId = players:GetUserIdFromNameAsync(intendedPlr)
local plyerStatues
local alreadyBanned
local success, errorMassage = pcall(function()
plyerStatues = banList:GetAsync(playerId)
end)
if plyerStatues.banned == true then --Error2
plyerStatues.banned = false
banRemoteReturn:FireClient(plr, command,"Successfully Unbanned")
return
else
banRemoteReturn:FireClient(plr, command,"Not Banned")
return
end
end
end)