The value BanDuration inside of the datastore is not updating when I run the unban function. Can someone help me figure out why.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DDS = game:GetService("DataStoreService");
local Players = game:GetService("Players");
local BanFunction = ReplicatedStorage:WaitForChild("Ban")
local BanStore = DDS:GetDataStore("BanStore", 2)
local secondsInADay = 86400
local unbanRemote = ReplicatedStorage:WaitForChild("Unban")
function BanFunction.OnServerInvoke(PlayerSentBy, Player, Reason, Duration)
local Success, Error = pcall(function()
BanStore:SetAsync(tostring(Player.UserId), {BanStart = os.time(), BanDuration = (Duration * secondsInADay), BanReason = Reason});
end)
Player:Kick(Reason);
if not Success then
warn("Not successful.")
end
end
function unbanRemote.OnServerInvoke(PlayerSentBy, Player, Duration)
BanStore:SetAsync(tostring(Player.UserId), {BanDuration = 0})
end
local function GetBan(Player)
local banData = BanStore:GetAsync(tostring(Player.UserId))
if banData and banData.BanDuration > 0 and banData.BanStart + banData.BanDuration > os.time() then
return banData.BanReason
end
return nil
end
Players.PlayerAdded:Connect(function(plr)
local IsBanned = GetBan(plr);
if IsBanned ~= nil then
plr:Kick("You are banned for ".. IsBanned);
else
end
end)