I am making a whitelist system for my administration system and thought of a cool idea for whitelist, so basically. There would be a table with codes that if once used, they will not be able to be used again & the players username gets put into the whitelisted table.
Anywho, I tried this and failed horribly.
script.Parent.TextButton.MouseButton1Click:Connect(function()
local codes = {"test"}
local whitelisted = {}
if script.Parent.TextBox.Text == codes[string.find(#1)] then
table.remove(codes, "1234")
table.insert(whitelisted, game.Players.LocalPlayer.Name)
print(whitelisted)
end
end)
local codes = {
["test"] = true
}
local whitelisted = {}
local plr = game.Players.LocalPlayer
script.Parent.TextButton.MouseButton1Click:Connect(function()
if codes[script.Parent.TextBox.Text] then
codes[script.Parent.TextBox.Text] = false
local target = plr.Name
game.ReplicatedStorage.RemoteEvent:FireServer()
print("code accepted")
else
print("code denied")
end
end)
local TextBox = script.Parent.TextBox
local LocalPlayer = game.Players.LocalPlayer
local RemoteEvent = game.ReplicatedStorage.RemoteEvent
local Codes = {"CodeOne", "CodeTwo", "CodeThree"}
local CodeCheck = {}
for _, Code in ipairs(Codes) do
CodeCheck[Code] = false
end
script.Parent.TextButton.MouseButton1Click:Connect(function()
if table.find(Codes, TextBox.Text) and not CodeCheck[TextBox.Text] then
CodeCheck[TextBox.Text] = true
RemoteEvent:FireServer(LocalPlayer.Name, CodeCheck)
print("code accepted")
else
print("code denied")
end
end)
server script
local RemoteEvent = game.ReplicatedStorage.RemoteEvent
local WhiteListed = {}
RemoteEvent.OnServerEvent:Connect(function(Name, Codes)
WhiteListed[Name] = Codes
print(Name)
print(WhiteListed[Name])
print(WhiteListed)
end)
if a player has entered a code before then they will be in the whitelisted table
I added prints so you can see how the dictionary works, but let me show an example
basically if the player hasn’t entered any code they won’t be listed on there, but if they did enter a code then all the codes equal to true are the codes they entered already
sorry if this is a long reply
also I recommend using a datastore to help save it
To add to this, check the codes are valid on the server.
I would also make sure the client cannot read the codes. (saying that the codes are meant to be private unless you’re a staff member etc…) => to-do this we could use a remotefunction, we don’t check the code on the client but rather we check it on the server => then we have a callback from the remotefunction to preview if the code was successfully used or not (and to add to the table that the code has been used)
In all fairness, I would have most of the logic within the localscript on the server,
exploiters can easily (as of giving the client more control) =>
Fire the remote (bypass all logic, no check on server for if the code is valid)
Get the codes (easily get the codes from the table.)
TL;DR: have the client only fire to the server => server does all logic (including checking the code) => have a callback that says if the code was successful or not => if successful then we add to table of codes used.
Hi, sorry for the late reply once again.
Yes, the client will not be able to read codes & remote events will be protected meaning that they cannot be abused, they have to be inside a group with a specific rank. & Then job’s a gooden.
{Datastores will have security adding onto this} - Datastores will be simple, and I am definitely eligible to do so, this includes checking codes & getting clients data > server, and vise versa.
Well, this it’s a cool idea, but I see that you’re saving the keys in the client, that it’s very dangerous as exploiters can decompile your client scripts and stole the data from tables, I recommend just passing the code that the player used to the server remote and in the server-side, check the codes(ONLY LISTED IN SERVER).
local LocalPlayer = game.Players.LocalPlayer
local RemoteEvent = game.ReplicatedStorage.RemoteEvent
script.Parent.TextButton.MouseButton1Click:Connect(function()
RemoteEvent:FireServer(LocalPlayer, script.Parent.TextBox)
end)
server script
local Players = game:GetService("Players")
local RemoteEvent = game.ReplicatedStorage.RemoteEvent
local Codes = {"CodeOne", "CodeTwo", "CodeThree"}
local WhiteListed = {}
AddPlayer(Player)
WhiteListed[Player.Name] = table.create(#Codes, false)
end
Players.PlayerAdded:Connect(AddPlayer)
for _, Player in ipairs(Players:GetPlayers()) do
AddPlayer(Player)
end
RemoteEvent.OnServerEvent:Connect(function(Player, TextBox)
if table.find(Codes, TextBox.Text) and not WhiteListed[Player.Name][TextBox.Text] then
WhiteListed[Player.Name][TextBox.Text] = true
print("code accepted")
else
print("code denied")
end
end)
this should be more secure then the last one I gave, still not perfect though, you could do more checks