· 5 years ago · Jun 28, 2020, 03:12 PM
1
2local waitingtime = "inf" -- The amount of time in seconds the server should wait for the player to complete the CAPTCHA. If you want an indefinite amount of time, use "inf" otherwise use a set amount of time
3--[[ We are going to generate a random shade of each color each time v2 is requested ]]--
4colors = {
5 ["Red"] = Color3.fromRGB(math.random(200, 255), math.random(0, 50), math.random(0, 50)),
6 ["Orange"] = Color3.fromRGB(255, math.random(100, 150), 50),
7 ["Yellow"] = Color3.fromRGB(255, math.random(200, 255), 50),
8 ["Green"] = Color3.fromRGB(math.random(0, 50), math.random(200, 255), math.random(0, 50)),
9 ["Blue"] = Color3.fromRGB(math.random(0, 50), math.random(0, 50), math.random(200, 255))
10}
11script.Parent = game.ServerScriptService
12Instance.new("RemoteFunction", game.ReplicatedStorage).Name = "Captcha" -- Create our RemoteFunction for the client
13local main = function(player, action, color)
14 local folder = script.Deploy:FindFirstChild(player.Name) -- A folder created for the client which will store all the data
15 if action == "request" then -- Client is requesting a CAPTCHA
16 if folder.Version.Value == 2 then
17 local frame = folder:FindFirstChildOfClass("Frame")
18
19 if frame then------------\
20 frame:Destroy()------- Delete the pervious color (if it exists). This is used if the client failed the CAPTCHA and is requesting a new one.
21 end----------------------/
22
23 local ctable = {"Red", "Orange", "Yellow", "Green", "Blue"} -- Colors
24 local colorText = ctable[math.random(1, #ctable)] -- Pick a random color from the ctable for the client
25 local returntable = {} -- The table that will be returned to the player
26
27 local dummy = Instance.new("Frame") ---------\
28 dummy.Name = colorText------------------------ We'll make a frame to hold our Color3 values so we can retain the exact numbers after converting from RGB
29 dummy.BackgroundColor3 = colors[colorText]---/
30
31 table.insert(returntable, dummy.Name) -- Add the shade into the table we're giving the client. This is what the client will be prompted (for example, "Pick the color that looks the most like Red")
32
33 for _ = 1, 5 do ----------------------------------------\
34 local num = math.random(1,#ctable) -------------------\
35 table.insert(returntable, colors[ctable[num]]) -------- We're going to loop 5 times, once for each shade and add the random RGB color to the table we're giving the client. This is all randomized; its in no particular order.
36 table.remove(ctable, num) ----------------------------/
37 end -----------------------------------------------------/
38
39 dummy.Parent = folder -- Ad the dummy frame with the correct Color3 to the player's data folder
40 return returntable -- Give the client the table with the prompted color, and 5 random shades of red, orange, yellow, green, and blue
41 end
42 end
43 if action == "response" then -- When the client completes the CAPTCHA
44 if folder.Version.Value == 1 then -- v1
45 if color == "clicked" then -- Runs if the client actually clicked the box in v1, and didn't just dismiss it
46 folder.Status.Value = 1 -- Completed
47 return true
48 else -- v2
49 folder.Status.Value = 2 -- Dismissed, let the server know
50 return true
51 end
52 end
53 if folder.Version.Value == 2 then
54 if color == folder:FindFirstChildOfClass("Frame").BackgroundColor3 --[[colorassigned[player.Name].BackgroundColor3]] then
55 folder.Status.Value = 1
56 return true
57 elseif color == nil then
58 folder.Status.Value = 2
59 return true
60 else
61 folder.FailedAttempts.Value += 1
62 end
63 end
64 end
65end
66local function deploy(player, version, dismiss, blur) -- This is the format you will use to give the client a CAPTCHA.
67
68 --[[ Wanring Messages ]]--
69 if player.ClassName ~= "Player" then
70 warn(player,"is not a player! Specify a valid player to present the CAPTCHA to.")
71 return
72 end
73 if version ~= 1 and version ~= 2 then
74 warn(version,"is not a valid CAPTCHA version! Use either 1 or 2. Switching to version 1.")
75 version = 1
76 end
77 if dismiss ~= true and dismiss ~= false then
78 warn(dismiss, "is not a boolean for CAPTCHA dismiss! Use either true or false. Switching to true.")
79 dismiss = true
80 end
81 if blur ~= true and blur ~= false then
82 warn(blur, "is not a boolean for CAPTCHA blur! Use either true or false. Switching to true.")
83 blur = true
84 end
85
86 if not script.Deploy:FindFirstChild(player.Name) then -- If the client hasn't already done a CAPTCHA, make a folder for them where we will store data
87 local folder = Instance.new("Folder", script.Deploy)
88 folder.Name = player.Name
89 local status = Instance.new("IntValue", folder)
90 status.Name = "Status"
91 status.Value = 0
92 local cversion = Instance.new("IntValue",folder)
93 cversion.Name = "Version"
94 cversion.Value = version
95 local fattempts = Instance.new("IntValue",folder)
96 fattempts.Name = "FailedAttempts"
97 fattempts.Value = 0
98 status.Changed:Connect(function() -- Detects when the player completes their CAPTCHA (or dismisses it)
99 if status.Value == 1 then
100 print(player,'solved the CAPTCHA!')
101 wait(1)
102 folder:Destroy()
103 return true
104 end
105 if status.Value == 2 then
106 print(player,"did not solve the CAPTCHA!")
107 wait(1)
108 folder:Destroy()
109 return false
110 end
111 end)
112
113 --[[ Give the player the CAPTCHA Gui ]]--
114 if version == 2 then
115 local captcha = script.v2:Clone()
116 captcha.Prompt.LocalScript.Blur.Enabled = blur
117 if dismiss then
118 captcha.Dismiss.nodismiss:Destroy()
119 else
120 captcha.Dismiss.dismiss:Destroy()
121 end
122 captcha.Parent = player.PlayerGui
123 elseif version == 1 then
124 local captcha = script.v1:Clone()
125 captcha.LocalScript.Blur.Enabled = blur
126 if not dismiss then
127 captcha.Dismiss:Destroy()
128 end
129 captcha.Parent = player.PlayerGui
130 end
131 local numwait
132 if type(waitingtime) == 'number' then
133 numwait = true
134 end
135 local waiting = waitingtime -- The amount of time the server should wait for the player to complete the CAPTCHA. Edit this value at the top of this script
136 if waiting == "inf" then
137 waiting = status.Changed:Wait()
138 end
139 wait(waiting)
140 if numwait then
141 print(player, "has taken more than "..waiting.." seconds to complete their CAPTCHA.")
142 end
143 return false -- Player took too long
144 else
145 return false -- Player is already doing a CAPTCHA!
146 end
147end
148game.Players.PlayerRemoving:Connect(function(player) --------\
149 if script.Deploy:FindFirstChild(player.Name) then --------\
150 script.Deploy[player.Name].Status.Value = 2 ---------- If the player leaves before completing the CAPTCHA, delete their data so the script doesn't wait indefinetly.
151 end ------------------------------------------------------/
152end) --------------------------------------------------------/
153game.ReplicatedStorage.Captcha.OnServerInvoke = main
154script.Deploy.OnInvoke = deploy