I roughly codded this server script using a community tutorial but it doesn’t seem to be working and I cannot figure out why. Any help is appreciated!!
local DataStoreService = game:GetService("DataStoreService")
local BannedUsers = DataStoreService:GetDataStore("BannedUsers")
local Players = game:GetService("Players")
local BlacklistedWords = {
"test"
}
local function Ban(Player)
local Success, Error = pcall(function()
BannedUsers:SetAsync(tostring(Player.UserId))
end)
end
game.Players.PlayerAdded:Connect(function(Player)
local IsBanned = Ban(Player.UserId)
if IsBanned ~= nil then
Player:Kick("You have been banned.")
end
Player.Chatted:Connect(function(ChattedMessage)
local Message = string.lower(ChattedMessage)
if table.find(BlacklistedWords, Message) then
Ban(Player.UserId)
Player:Kick("You have been banned.")
end
end)
end)
in the Ban function after the entire pcall function, put:
return Error
aren’t you supposed to put GetAsync
The ban function is used to set the player’s user id into the datastore in the 5th line from the end
local DataStoreService = game:GetService("DataStoreService")
local BannedUsers = DataStoreService:GetDataStore("BannedUsers")
local Players = game:GetService("Players")
local BlacklistedWords = {
"test"
}
local function BanPlayer(UserId)
local Success, Error = pcall(function()
BannedUsers:SetAsync(tostring(UserId), true)
end)
end
local function CheckIfBanned(UserId)
local Success, Error = pcall(function()
return BannedUsers:GetAsync(tostring(UserId))
end)
if not Success then
local Attempts = 0
repeat task.wait(1)
Success, Error = pcall(function()
return BannedUsers:GetAsync(tostring(UserId))
end)
Attempts += 1
until Success or Attempts >= 5
end
if Success then
return Error
end
end
game.Players.PlayerAdded:Connect(function(Player)
local IsBanned = CheckIfBanned(Player.UserId)
if IsBanned ~= nil then
Player:Kick("You have been banned.")
end
Player.Chatted:Connect(function(ChattedMessage)
local Message = string.lower(ChattedMessage)
if table.find(BlacklistedWords, Message) then
BanPlayer(Player.UserId)
Player:Kick("You have been banned.")
end
end)
end)
1 Like