iIt works!!
now… how do i make ban system???
is like this?
--// Services \\--
local DSS = game:GetService("DataStoreService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--// Variables \\--
local Admins = require(script.Parent.Settings).Ranks
--// DataStores \\--
local BannedPlayers = DSS:GetDataStore("BannedPlayers")
--// Functions \\--
function IsAdmin(player)
for _, v in pairs(Admins) do
if player.UserId == v then
return true
end
end
return false
end
function Time()
end
--// Script \\--
game.Players.PlayerAdded:Connect(function(player)
if IsAdmin(player) == true then
local ui = script.AdminGUI:Clone()
ui.Parent = player.PlayerGui
end
player.PlayerGui.ChildAdded:Connect(function(child)
if child:IsA("ScreenGui") and child.Name == script.AdminGUI.Name and IsAdmin(player) == false then
player:Kick("Reason: \n Exploiting to AdminScreen. \n Kicked By System")
end
end)
end)
ReplicatedStorage.Remotes.Kick.OnServerEvent:Connect(function(plr, reason)
plr:Kick(reason)
end)
--// Services \\--
local DSS = game:GetService("DataStoreService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MessagingService = game:GetService("MessagingService")
--// Variables \\--
local Admins = require(script.Parent.Settings).Ranks
--// DataStores \\--
local BannedPlayers = DSS:GetDataStore("BannedPlayers")
--// Functions \\--
function IsAdmin(player)
for _, v in pairs(Admins) do
if player.UserId == v then
return true
end
end
return false
end
function Time()
end
--// Script \\--
game.Players.PlayerAdded:Connect(function(player)
if IsAdmin(player) == true then
local ui = script.AdminGUI:Clone()
ui.Parent = player.PlayerGui
end
player.PlayerGui.ChildAdded:Connect(function(child)
if child:IsA("ScreenGui") and child.Name == script.AdminGUI.Name and IsAdmin(player) == false then
player:Kick("Reason: \n Exploiting to AdminScreen. \n Kicked By System")
end
end)
end)
ReplicatedStorage.Remotes.Kick.OnServerEvent:Connect(function(plr, reason)
plr:Kick("You've Been Kicked \n Reason: \n"..reason)
end)
ReplicatedStorage.Remotes.Ban.OnServerEvent:Connect(function(plr, reason, duration)
plr:Kick("You've Been Banned \n Reason: \n"..reason.."\n Duration: "..duration)
BannedPlayers:SetAsync(plr.UserId,{
['Name'] = plr.Name,
['UserId'] = plr.UserId
})
MessagingService:PublishAsync("BANNED_PLAYERS")
end)
First, in the ban event, save the ban first with pcalls and if the request is sent and everything is fine then you would kick them. I don’t really know what is the purpose of the publishasync function because you already kicked the player.
ReplicatedStorage.Remotes.Ban.OnServerEvent:Connect(function(plr, reason, duration)
plr:Kick("You've Been Banned \n Reason: \n"..reason.."\n Duration: "..duration)
local s, e = pcall(function()
BannedPlayers:SetAsync(plr.UserId,{['Name'] = plr.Name,['UserId'] = plr.UserId})
end)
if not s then TestService:Error(e)
end)
ReplicatedStorage.Remotes.Ban.OnServerEvent:Connect(function(plr, reason, duration)
local s, e = pcall(function()
BannedPlayers:SetAsync(plr.UserId,{['Name'] = plr.Name,['UserId'] = plr.UserId})
end)
if not s then
error(e)
else
plr:Kick("You've Been Banned \n Reason: \n"..reason.."\n Duration: "..duration)
end
end)
However, the code above is purely for one-server communications aka, it doesn’t support the following concept “A kick request is sent → The player isn’t in the same server you are in → The system sends a messaging service request → the player is kicked” but you can achieve that with messaging service though.
i mean, when the event gets fired he will kick the player and when he trys again join he will get kicked by the script and no is not every time a player joins. is every time the ban script fire it.