(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.)
local DataStore = game:GetService("DataStoreService") local UTGJDS = DataStore:GetDataStore("classified") local remote = game.ReplicatedStorage:WaitForChild("UTGJRemoteEvent") local code = "classified" game.Players.PlayerAdded:Connect(function(plr) plr.Chatted:Connect(function(msg, recipient) if string.lower(msg) == string.lower("giveutgj") and not recipient then local getallowed, atable = pcall(function() return UTGJDS:GetAsync("Username") end) if getallowed then for i, v in pairs(atable) do if plr.Name == v then local cloned = script:WaitForChild("AccessUI"):Clone() cloned.Parent = plr:WaitForChild("PlayerGui") end end else warn("UTGJ get allowed table Datastore Error! Now Retrying..") for i = 1, 5 do local getallowed2, atable2 = pcall(function() return UTGJDS:GetAsync("Username") end) if getallowed2 then for i, v in pairs(atable2) do if plr.Name == v then local cloned = script:WaitForChild("AccessUI"):Clone() cloned.Parent = plr:WaitForChild("PlayerGui") end end else warn("UTGJ Update Datstore Error! Retrying..") end end end end end) end) remote.OnServerInvoke = function(plr, action, username, vcode) if vcode == code then if action == "Whitelist" then local dstable local getsuccsess, ctable = pcall(function() return UTGJDS:GetAsync("Username") end) if getsuccsess then dstable = ctable else if type(ctable) ~= "table" and type(ctable) == 'string' then warn("UTGJ whitelisting Datastore Error! Now Retrying..") end for i = 1, 5 do local getsuccsess2, ctable2 = pcall(function() return UTGJDS:GetAsync("Username") end) if getsuccsess2 then dstable = ctable else warn("UTGJ whitelisting Datstore Error! Retrying..") end end end if dstable then table.insert(dstable, #dstable + 1, username) local updatesuccess, err = pcall(function() return UTGJDS:UpdateAsync("Username", dstable) end) if updatesuccess then print("Successfully updated UTGJ username whitelist. New user added: "..username) return true else warn("UTGJ Update Datastore Error! Now Retrying..") for i = 1, 5 do local getupdate2, err2 = pcall(function() return UTGJDS:UpdateAsync("Username", dstable) end) if getupdate2 then print("Successfully updated UTGJ username whitelist. New user added: "..username) return true else warn("UTGJ Update Datstore Error! Retrying..") end end end end return false elseif action == "Unwhitelist" then local dstableunwhitelist local getsuccsessunwhitelist, dtable = pcall(function() return UTGJDS:GetAsync("Username") end) if getsuccsessunwhitelist then dstableunwhitelist = dtable else warn("UTGJ unwhitelisting Datastore Error! Now Retrying..") for i = 1, 5 do local getsuccsessunwhitelist2, dtable2 = pcall(function() return UTGJDS:GetAsync("Username") end) if getsuccsessunwhitelist2 then dstableunwhitelist = dtable2 else warn("UTGJ unwhitelisting Datstore Error! Retrying..") end end end if dstableunwhitelist then for a, b in pairs(dstableunwhitelist) do if (username == dstableunwhitelist[a]) then table.remove(dstableunwhitelist, a) end end local updatesuccessunwhitelist, errunwhitelist = pcall(function() return UTGJDS:UpdateAsync("Username", dstableunwhitelist) end) if updatesuccessunwhitelist then print("Successfully updated UTGJ username unwhitelist. Removed user: "..username) return true else warn("UTGJ Update Datastore Error! Now Retrying..") for i = 1, 5 do local updateunwhitelist2, errunwhitelist2 = pcall(function() return UTGJDS:UpdateAsync("Username", dstableunwhitelist) end) if updateunwhitelist2 then print("Successfully updated UTGJ username unwhitelist. Removed user: "..username) return true else warn("UTGJ Update Datstore Error! Retrying..") end end end end return false end elseif action == "GetUserWhitelisted" then local getusers, usertable = pcall(function() return UTGJDS:GetAsync("Username") end) if getusers then return true, usertable else warn("UTGJ get users whitelisted Datastore Error! Now Retrying..") for i = 1, 5 do local getusers2, usertable2 = pcall(function() return UTGJDS:GetAsync("Username") end) if getusers2 then return true, usertable2 else warn("UTGJ Update Datstore Error! Retrying..") end end end return false else warn("Unauthorized user "..plr.Name.." tried to use UTGJ Whitelister/Unwhitelister.") end end
(I am sorry if it's hard to read)
GUI Code:
local remote = game.ReplicatedStorage:WaitForChild("UTGJRemoteEvent") local code = "" local openclose = script.Parent:WaitForChild("Open") local frame = script.Parent:WaitForChild("Frame") local usertextbox = frame:WaitForChild("Username") local whitelist = frame:WaitForChild("Whitelist") local unwhitelist = frame:WaitForChild("Unwhitelist") local status = frame:WaitForChild("status") local getuserframe = script.Parent:WaitForChild("GetUsersUTGJ") local textgetuser = getuserframe:WaitForChild("Users") local getuserbutton = getuserframe:WaitForChild("GetUsers") openclose.MouseButton1Click:Connect(function() if frame.Visible == true then frame.Visible = false getuserframe.Visible = false else frame.Visible = true getuserframe.Visible = true end end) whitelist.MouseButton1Click:Connect(function() if usertextbox.Text ~= "" or usertextbox.Text ~= " " or usertextbox.Text ~= "ItzEthanPlayz_YT" or usertextbox.Text ~= "hellomehaOof" then local sucess = remote:InvokeServer("Whitelist", usertextbox.Text, code) if sucess then status.Text = "Successfully whitelisted the user." status.TextColor3 = Color3.fromRGB(0, 255, 0) else status.Text = "Failed while whitelisting the user." status.TextColor3 = Color3.fromRGB(255, 0, 0) end end end) unwhitelist.MouseButton1Click:Connect(function() if usertextbox.Text ~= "" or usertextbox.Text ~= " " or usertextbox.Text ~= "ItzEthanPlayz_YT" or usertextbox.Text ~= "hellomehaOof" then local sucess = remote:InvokeServer("Unwhitelist", usertextbox.Text, code) if sucess then status.Text = "Successfully unwhitelisted the user." status.TextColor3 = Color3.fromRGB(0, 255, 0) else status.Text = "Failed while unwhitelisting the user." status.TextColor3 = Color3.fromRGB(255, 0, 0) end end end) getuserbutton.MouseButton1Click:Connect(function() local sucess, usertable = remote:InvokeServer("GetUserWhitelisted", "a", code) if sucess then if type(usertable) == "table" then for i, v in pairs(usertable) do if textgetuser.Text ~= "" then textgetuser.Text = textgetuser.Text.." , "..v else textgetuser.Text = v end end else textgetuser.Text = "Error. (Not a table.)" end else textgetuser.Text = "An error has occured in the serverside script. Please try again.)" end end)
(Also the string replaced with "no" is me and my friend)
Can anyone help please?
Thanks, Ethan