I have a function that is meant to temporarily ban players with given parameters. I have tried solutions from around devforum but to no avail. Here is the function code and the code calling the function.
Other functions work just fine…
-- CALLED FUNCTION --
function addBanName(plr, plrtoBan, reason, banlength)
local returning
local id = getId(plrtoBan)
if id then
if id ~= "error" then
if math.floor(banlength) < 3 then
local info
local success, err = pcall(function()
bans:SetAsync(id .. "_Banned", {
["Banner"] = plr,
["Date"] = os.date("%d") .. "/" .. os.date("%m") .. "/" .. os.date("%y") .. " at " .. os.date("%H") .. ":" .. os.date("%M") .. " UTC",
["Reason"] = game:GetService("Chat"):FilterStringForBroadcast(reason, plrService:FindFirstChild(plr)),
["Victim"] = plrtoBan,
["Appealable"] = "no",
["TempBan"] = math.floor(banlength) .. " day(s)",
["TempBanNumber"] = os.time() + math.floor(day * math.floor(banlength))
})
end)
if success then
if plrService:FindFirstChild(plrtoBan) then
game:GetService("TeleportService"):Teleport(7874256009, plrService:FindFirstChild(plrtoBan))
wait()
plrService:FindFirstChild(plrtoBan):Kick("You have been temporarily banned. Please wait to be teleported for more information.")
returning = true
end
else
returning = false
end
else
local info
local success, err = pcall(function()
bans:SetAsync(id .. "_Banned", {
["Banner"] = plr,
["Date"] = os.date("%d") .. "/" .. os.date("%m") .. "/" .. os.date("%y") .. " at " .. os.date("%H") .. ":" .. os.date("%M") .. " UTC",
["Reason"] = game:GetService("Chat"):FilterStringForBroadcast(reason, plrService:FindFirstChild(plr)),
["Victim"] = plrtoBan,
["Appealable"] = "yes",
["TempBan"] = math.floor(banlength) .. " day(s)",
["TempBanNumber"] = os.time() + math.floor(day * math.floor(banlength))
})
end)
if success then
if plrService:FindFirstChild(plrtoBan) then
game:GetService("TeleportService"):Teleport(7874256009, plrService:FindFirstChild(plrtoBan))
wait()
plrService:FindFirstChild(plrtoBan):Kick("You have been temporarily banned. Please wait to be teleported for more information.")
returning = true
end
else
returning = false
end
end
else
returning = false
end
else
returning = false
end
return returning
end
-- CALLED FUNCTION --
-- CALLING FUNCTION --
local addbannow = addBanName(plr.Name, name, reasonstring, banlength)
local requests = 0
repeat wait()
requests += 1
until addbannow or requests == 200
if addbannow == true then
game:GetService("ReplicatedStorage").SendChatMessage:FireClient(plr, "Successfully banned user "
.. name .. " with ID " .. getId(name) .. "\nLength: " .. banlength .. " days\nReason: " .. reasonstring)
debounceC[plr.Name]:Destroy()
else
game:GetService("ReplicatedStorage").SendChatMessage:FireClient(plr, "There was an error banning this player.\nPlease try again.")
debounceC[plr.Name]:Destroy()
end
-- CALLING FUNCTION --