I’m making a anti cheat for my game and I’m working on a warning system, I made a datastore save script however whenever the server adds me 1 warning and I end the session, if I rejoin I have 0 warnings.
Script
local warnData = game:GetService("DataStoreService"):GetDataStore("warns1741414__41JFQFIQJADA7AD7A918E")
game.Players.PlayerAdded:Connect(function(plr)
local AACFolder = Instance.new("Folder")
AACFolder.Name = "AAC"
AACFolder.Parent = plr
local warns = Instance.new("NumberValue")
warns.Name = "Warnings"
warns.Parent = AACFolder
local data
local success, errormessage = pcall(function()
data = warnData:GetAsync(plr.UserId)
end)
if success then
warns.Value = data
else
warn("[AAC:createfolders] Unexpected Error: Couldn't load warn data")
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local data = plr.AAC.Warnings.Value
local success, errormessage = pcall(function()
warnData:SetAsync(plr.UserId, data)
end)
if success then
print("[AAC] Registered warn data for "..plr.Name.." using USER_ID ("..plr.UserId..")")
else
warn("[AAC:createfolders_critical] Could not save data for "..plr.UserId)
error("[AAC:createfolders_critical] "..errormessage)
end
end)
if success then
if data then
warns.Value = data
else
warns.Value = 0 -- the player is new
end
else
warn("[AAC:createfolders] Unexpected Error: Couldn't load warn data")
end
The warning’s value is changed in a serversided script, I just have to say a message and it’s adds the stat BEFORE kicking me, I can send the code if needed
local dds = game:GetService("DataStoreService")
local banData = dds:GetDataStore(game.CreatorId.."CHANGETHIS".."_aac")
game.Players.PlayerAdded:Connect(function(plr)
local warns = plr:WaitForChild("AAC"):WaitForChild("Warnings").Value
if banData:GetAsync(plr.UserId,true) then
plr:Kick("\nServer Connection Failed\nYou have been caught exploiting and have been permanently banned. If this is a error, please contact a admin.")
else
plr.Chatted:Connect(function(msg)
local arg = msg:split(" ")
if msg == ";" then
if warns == 3 then
banData:SetAsync(plr.UserId,true)
plr:Kick("Session forcefully ended")
else
warns += 1
plr:Kick("Disconnected from server: the usage of ';' is banned")
end
end
end)
end
end)
Don’t mind the fact that I don’t use string.find, but this is the script that adds the warning to me