The title!
No errors, everything works fine I just want to know what would be good to remove/add. This could be for any reason.
local module = {}
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("TestAsyncNumber__3__3__4__3__4__253225")
local SessionData = require(script.Parent.SessionData)
module.PlayersLoaded = {}
Players.PlayerAdded:Connect(function(player)
local stats = Instance.new("Folder")
stats.Name = "stats"
stats.Parent = player
local Jumps = Instance.new("NumberValue")
Jumps.Parent = stats
Jumps.Name = "Jumps"
Jumps.Value = 0
local Points = Instance.new("NumberValue")
Points.Parent = stats
Points.Name = "Points"
Points.Value = 0
local Data = nil
local succ, err = pcall(function()
Data = DataStore:GetAsync(player.UserId)
end)
if err then warn(err) end
if Data ~= nil then
if Data["Banned"] == 1 then
local TimeLeft1 = os.time() - Data["TimeOfBan"]
local TimeLeft2 = (1 * 86400) - TimeLeft1
local TimeLeft = math.round(TimeLeft2 / 86400)
if TimeLeft2 <= 0 then
DataStore:RemoveAsync(player.UserId)
SessionData[player.Name] = {}
SessionData[player.Name]["Jumps"] = math.random(30, 75)
Jumps.Value = SessionData[player.Name]["Jumps"]
SessionData[player.Name]["Points"] = 0
Points.Value = SessionData[player.Name]["Points"]
SessionData[player.Name]["Banned"] = 0
SessionData[player.Name]["TimeOfBan"] = 0
module.PlayersLoaded[player.Name] = true
return
end
if TimeLeft == 1 then
player:Kick("You ran out of jumps! \nYour jumps will reset in ".. TimeLeft .." day!")
elseif TimeLeft < 1 then
TimeLeft = math.round(TimeLeft2 / 3600)
if TimeLeft == 1 then
player:Kick("You ran out of jumps! \nYour jumps will reset in ".. TimeLeft .." hour!")
elseif TimeLeft > 1 then
player:Kick("You ran out of jumps! \nYour jumps will reset in ".. TimeLeft .." hours!")
elseif TimeLeft < 1 then
TimeLeft = math.round(TimeLeft2 / 60)
if TimeLeft == 1 then
player:Kick("You ran out of jumps! \nYour jumps will reset in ".. TimeLeft .." minute!")
elseif TimeLeft > 1 then
player:Kick("You ran out of jumps! \nYour jumps will reset in ".. TimeLeft .." minutes!")
end
end
end
return
end
if Data["Banned"] == 2 then
player:Kick("You have been banned by a mod/admin! Appeal in our discord server.")
return
end
SessionData[player.Name] = Data
Jumps.Value = Data["Jumps"]
Points.Value = Data["Points"]
else
SessionData[player.Name] = {}
SessionData[player.Name]["Jumps"] = math.random(30, 75)
Jumps.Value = SessionData[player.Name]["Jumps"]
SessionData[player.Name]["Points"] = 0
Points.Value = SessionData[player.Name]["Points"]
SessionData[player.Name]["Banned"] = 0
SessionData[player.Name]["TimeOfBan"] = 0
end
module.PlayersLoaded[player.Name] = true
end)
local function saveData(player)
if player == nil then return end
if SessionData[player.Name] == nil then return end
local succ, err = pcall(function()
DataStore:SetAsync(player.UserId, SessionData[player.Name])
end)
if err then warn(err) end
SessionData[player.Name] = nil
end
local function onBindToClose()
local RunService = game:GetService("RunService")
if RunService:IsStudio() then return end
for _, player in pairs(Players:GetPlayers()) do
saveData(player)
end
end
function module.unbanAdminCommand(player, targetID)
local Data = nil
local succ, err = pcall(function()
Data = DataStore:GetAsync(targetID)
end)
if err then warn(err) end
if Data ~= nil then
if Data["Banned"] == 1 then
DataStore:RemoveAsync(targetID)
end
game:GetService("ReplicatedStorage").Events.Noti:FireClient(player, "success")
return
end
game:GetService("ReplicatedStorage").Events.Noti:FireClient(player, "failed")
end
Players.PlayerRemoving:Connect(saveData)
game:BindToClose(onBindToClose)
return module