Greetings, I was making a ban system for my game and it seems to appear not to work. Assistance would be very helpful.
local DatastoreService = game:GetService("DataStoreService")
local MessagingService = game:GetService("MessagingService")
local AdminStore = DatastoreService:GetDataStore("Administrator")
local BannedPlayers = DatastoreService:GetDataStore("BannedPlayers")
local AdminRemotes = game.ReplicatedStorage.AdminRemotes
local function disp_time(t, plr)
local data = BannedPlayers:GetAsync(plr.UserId)
local duration = data.Time
local days = math.floor(t/86400)
local hours = math.floor(math.modf(t, 86400)/3600)
local minutes = math.floor(math.modf(t, 3600)/60)
end
AdminRemotes.Ban.OnServerEvent:Connect(function(sender, target, reason, duration)
if AdminStore:GetAsync(sender.UserId) then
local uid = game.Players:GetUserIdFromNameAsync(target)
BannedPlayers:SetAsync(uid, {
["Time"] = duration,
["Moderator"] = sender.Name,
["Reason"] = reason
})
local data = {
["target"] = target,
}
MessagingService:PublishAsync("BAN_PLAYER", data)
else
BannedPlayers:SetAsync(sender.UserId, {
["Time"] = -1,
["Moderator"] = "Server: ",
["Reason"] = "Exploiting is not allowed."
})
sender:Kick()
end
end)
AdminRemotes.CheckAdministrator.OnServerInvoke = function(sender)
local isAdmin = AdminStore:GetAsync(sender.UserId)
if isAdmin then
return true
else
return false
end
end
AdminRemotes.Kick.OnServerEvent:Connect(function(sender, target, reason)
if AdminStore:GetAsync(sender.UserId) then
local player = game.Players:FindFirstChild(target)
if player then
player:Kick("reason")
end
else
BannedPlayers:SetAsync(sender.UserId, {
["Time"] = -1,
["Moderator"] = "Server: ",
["Reason"] = "Exploiting is not allowed."
})
sender:Kick()
end
end)
AdminRemotes.Ban.OnServerEvent:Connect(function(sender, target, reason, duration)
if AdminStore:GetAsync(sender.UserId) then
local uid = game.Players:GetUserIdFromNameAsync(target)
if BannedPlayers:GetAsync(uid) then
BannedPlayers:RemoveAsync(uid)
end
else
BannedPlayers:SetAsync(sender.UserId, {
["Time"] = -1,
["Moderator"] = "Server: ",
["Reason"] = "Exploiting is not allowed."
})
sender:Kick()
end
end)
game.Players.PlayerAdded:Connect(function(player)
local bandata = BannedPlayers:GetAsync(player.UserId)
local t = os.time()
if bandata then
if bandata.Time ~= -1 then
if t >= bandata.Time then
BannedPlayers:RemoveAsync(player.UserId)
else
player:kick(disp_time())
end
end
end
end)
Edit: When I fire the ban event it kicks me and when I rejoin it fails to save that data, from the previous server.
Only thing that is provided via console is,
There is a whitelist system connected to this ban system, and will be adding that in too.
local UIS = game:GetService("UserInputService")
local checkadmin = game.ReplicatedStorage:WaitForChild("AdminRemotes").CheckAdministrator
local plr = game.Players.LocalPlayer
local function isAdministrator()
local AdminStatus = checkadmin:InvokeServer()
if not AdminStatus then
script.Parent:Destroy()
end
end
UIS.InputBegan:Connect(function(key, gameprocessed)
if not gameprocessed then
if key.KeyCode == Enum.KeyCode.C then
script.Parent.Main.Visible = not script.Parent.Main.Visible
end
end
end)
isAdministrator()