[SOLVED] This whitelist system that uses Datastore is not working and doesn't output any error?
Asked by
4 years ago Edited 4 years ago
(Edit: fixed OnServerEvent and updated the GUI Code)
So I am making a Datastore whitelisting system, basically I can whitelist, unwhitelist, or view who is whitelisted via a GUI.
How my system works is to use RemoteFunctions (to return stuff, also don't get confused if the RemoteFunction name is UTGJRemoteEvent)
The problem is that my code doesn't work and doesn't output any error. And yes I enabled studio API access. (Because I was testing it on studio). When I clicked whitelist, unwhitelist, or get users whitelisted on my GUI, all of them say that is failed (I made a status system that can say wether it succeded or failed.), and my output says that it failed as well (I added a warn everytime Datastore fails)
Server script: (the datastore and code is classified.)
001 | local DataStore = game:GetService( "DataStoreService" ) |
002 | local UTGJDS = DataStore:GetDataStore( "classified" ) |
004 | local remote = game.ReplicatedStorage:WaitForChild( "UTGJRemoteEvent" ) |
005 | local code = "classified" |
007 | game.Players.PlayerAdded:Connect( function (plr) |
008 | plr.Chatted:Connect( function (msg, recipient) |
009 | if string.lower(msg) = = string.lower( "giveutgj" ) and not recipient then |
010 | local getallowed, atable = pcall ( function () |
011 | return UTGJDS:GetAsync( "Username" ) |
015 | for i, v in pairs (atable) do |
016 | if plr.Name = = v then |
017 | local cloned = script:WaitForChild( "AccessUI" ):Clone() |
018 | cloned.Parent = plr:WaitForChild( "PlayerGui" ) |
022 | warn( "UTGJ get allowed table Datastore Error! Now Retrying.." ) |
024 | local getallowed 2 , atable 2 = pcall ( function () |
025 | return UTGJDS:GetAsync( "Username" ) |
029 | for i, v in pairs (atable 2 ) do |
030 | if plr.Name = = v then |
031 | local cloned = script:WaitForChild( "AccessUI" ):Clone() |
032 | cloned.Parent = plr:WaitForChild( "PlayerGui" ) |
036 | warn( "UTGJ Update Datstore Error! Retrying.." ) |
044 | remote.OnServerInvoke = function (plr, action, username, vcode) |
045 | if vcode = = code then |
046 | if action = = "Whitelist" then |
048 | local getsuccsess, ctable = pcall ( function () |
049 | return UTGJDS:GetAsync( "Username" ) |
055 | if type (ctable) ~ = "table" and type (ctable) = = 'string' then |
056 | warn( "UTGJ whitelisting Datastore Error! Now Retrying.." ) |
059 | local getsuccsess 2 , ctable 2 = pcall ( function () |
060 | return UTGJDS:GetAsync( "Username" ) |
066 | warn( "UTGJ whitelisting Datstore Error! Retrying.." ) |
072 | table.insert(dstable, #dstable + 1 , username) |
073 | local updatesuccess, err = pcall ( function () |
074 | return UTGJDS:UpdateAsync( "Username" , dstable) |
077 | if updatesuccess then |
078 | print ( "Successfully updated UTGJ username whitelist. New user added: " ..username) |
081 | warn( "UTGJ Update Datastore Error! Now Retrying.." ) |
083 | local getupdate 2 , err 2 = pcall ( function () |
084 | return UTGJDS:UpdateAsync( "Username" , dstable) |
088 | print ( "Successfully updated UTGJ username whitelist. New user added: " ..username) |
091 | warn( "UTGJ Update Datstore Error! Retrying.." ) |
097 | elseif action = = "Unwhitelist" then |
098 | local dstableunwhitelist |
099 | local getsuccsessunwhitelist, dtable = pcall ( function () |
100 | return UTGJDS:GetAsync( "Username" ) |
103 | if getsuccsessunwhitelist then |
104 | dstableunwhitelist = dtable |
106 | warn( "UTGJ unwhitelisting Datastore Error! Now Retrying.." ) |
108 | local getsuccsessunwhitelist 2 , dtable 2 = pcall ( function () |
109 | return UTGJDS:GetAsync( "Username" ) |
112 | if getsuccsessunwhitelist 2 then |
113 | dstableunwhitelist = dtable 2 |
115 | warn( "UTGJ unwhitelisting Datstore Error! Retrying.." ) |
120 | if dstableunwhitelist then |
121 | for a, b in pairs (dstableunwhitelist) do |
122 | if (username = = dstableunwhitelist [ a ] ) then |
123 | table.remove(dstableunwhitelist, a) |
126 | local updatesuccessunwhitelist, errunwhitelist = pcall ( function () |
127 | return UTGJDS:UpdateAsync( "Username" , dstableunwhitelist) |
130 | if updatesuccessunwhitelist then |
131 | print ( "Successfully updated UTGJ username unwhitelist. Removed user: " ..username) |
134 | warn( "UTGJ Update Datastore Error! Now Retrying.." ) |
136 | local updateunwhitelist 2 , errunwhitelist 2 = pcall ( function () |
137 | return UTGJDS:UpdateAsync( "Username" , dstableunwhitelist) |
140 | if updateunwhitelist 2 then |
141 | print ( "Successfully updated UTGJ username unwhitelist. Removed user: " ..username) |
144 | warn( "UTGJ Update Datstore Error! Retrying.." ) |
151 | elseif action = = "GetUserWhitelisted" then |
152 | local getusers, usertable = pcall ( function () |
153 | return UTGJDS:GetAsync( "Username" ) |
157 | return true , usertable |
159 | warn( "UTGJ get users whitelisted Datastore Error! Now Retrying.." ) |
161 | local getusers 2 , usertable 2 = pcall ( function () |
162 | return UTGJDS:GetAsync( "Username" ) |
166 | return true , usertable 2 |
168 | warn( "UTGJ Update Datstore Error! Retrying.." ) |
174 | warn( "Unauthorized user " ..plr.Name.. " tried to use UTGJ Whitelister/Unwhitelister." ) |
(I am sorry if it's hard to read)
GUI Code:
01 | local remote = game.ReplicatedStorage:WaitForChild( "UTGJRemoteEvent" ) |
04 | local openclose = script.Parent:WaitForChild( "Open" ) |
05 | local frame = script.Parent:WaitForChild( "Frame" ) |
06 | local usertextbox = frame:WaitForChild( "Username" ) |
07 | local whitelist = frame:WaitForChild( "Whitelist" ) |
08 | local unwhitelist = frame:WaitForChild( "Unwhitelist" ) |
09 | local status = frame:WaitForChild( "status" ) |
10 | local getuserframe = script.Parent:WaitForChild( "GetUsersUTGJ" ) |
11 | local textgetuser = getuserframe:WaitForChild( "Users" ) |
12 | local getuserbutton = getuserframe:WaitForChild( "GetUsers" ) |
14 | openclose.MouseButton 1 Click:Connect( function () |
15 | if frame.Visible = = true then |
17 | getuserframe.Visible = false |
20 | getuserframe.Visible = true |
24 | whitelist.MouseButton 1 Click:Connect( function () |
25 | if usertextbox.Text ~ = "" or usertextbox.Text ~ = " " or usertextbox.Text ~ = "ItzEthanPlayz_YT" or usertextbox.Text ~ = "hellomehaOof" then |
26 | local sucess = remote:InvokeServer( "Whitelist" , usertextbox.Text, code) |
29 | status.Text = "Successfully whitelisted the user." |
30 | status.TextColor 3 = Color 3. fromRGB( 0 , 255 , 0 ) |
32 | status.Text = "Failed while whitelisting the user." |
33 | status.TextColor 3 = Color 3. fromRGB( 255 , 0 , 0 ) |
38 | unwhitelist.MouseButton 1 Click:Connect( function () |
39 | if usertextbox.Text ~ = "" or usertextbox.Text ~ = " " or usertextbox.Text ~ = "ItzEthanPlayz_YT" or usertextbox.Text ~ = "hellomehaOof" then |
40 | local sucess = remote:InvokeServer( "Unwhitelist" , usertextbox.Text, code) |
43 | status.Text = "Successfully unwhitelisted the user." |
44 | status.TextColor 3 = Color 3. fromRGB( 0 , 255 , 0 ) |
46 | status.Text = "Failed while unwhitelisting the user." |
47 | status.TextColor 3 = Color 3. fromRGB( 255 , 0 , 0 ) |
52 | getuserbutton.MouseButton 1 Click:Connect( function () |
53 | local sucess, usertable = remote:InvokeServer( "GetUserWhitelisted" , "a" , code) |
56 | if type (usertable) = = "table" then |
57 | for i, v in pairs (usertable) do |
58 | if textgetuser.Text ~ = "" then |
59 | textgetuser.Text = textgetuser.Text.. " , " ..v |
65 | textgetuser.Text = "Error. (Not a table.)" |
68 | textgetuser.Text = "An error has occured in the serverside script. Please try again.)" |
(Also the string replaced with "no" is me and my friend)
Can anyone help please?
Thanks, Ethan