Basically, I have been trying to make a code that will ban you if you die (personal project). I have seen some code on it, and have attempted to modify it. However, one way or another, I run into errors. Help would be much appreciated!
function BanPlayer(userid,timeinseconds,reason)
if game.Players:GetPlayerByUserId(userid) then
timeleft = timeinseconds
hours = math.floor(timeleft/3600)
hs = timeleft % 3600
mins = math.floor(hs/60)
secsleft = hs%60
game.Players:GetPlayerByUserId(userid):Kick(reason.. " in: "..hours.." hours, "..mins.." mins, and "..math.floor(secsleft).. " seconds.")
local g,b = pcall(function()
bans:SetAsync("plr_"..tostring(userid),{os.time(),reason,timeinseconds})
end)
if g then
print("succesfully banned player.")
else
warn("error setting ban datastore: "..b)
bans:SetAsync("plr_"..tostring(userid),{os.time(),reason,timeinseconds}) -- attempt agian.
end
else
local g,b = pcall(function()
bans:SetAsync("plr_"..tostring(userid),{os.time(),reason,timeinseconds})
end)
if g then
print("succesfully banned player.")
else
warn("error setting ban datastore: "..b)
bans:SetAsync("plr_"..tostring(userid),{os.time(),reason,timeinseconds}) -- attempt agian.
end
end
end
game.Players.PlayerAdded:Connect(function(plr)
if bans:GetAsync("plr_"..plr.UserId,{os.time(),reason,timeinseconds}) then
plr:Kick(reason.. " in: "..hours.." hours, "..mins.." mins, and "..math.floor(secsleft).. " seconds.")
end
plr.CharacterAdded:Connect(function(char)
char:WaitForChild("Humanoid").Died:Connect(function()
BanPlayer(plr.UserId,3600,"You have been banned cause you died. Expires")
end)
end)
end)```