generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: UnBan

Previous Thread :: Next Thread 
ColdUndermined is not online. ColdUndermined
Joined: 25 Jan 2010
Total Posts: 1819
31 Jul 2015 10:27 PM
So... Here is my ban script. How would I make it delete a table for a specific player if another event gets fired to make a 'Unban'?

local DataStore = game:GetService("DataStoreService"):GetDataStore("Ban")

--// Save Data

local Ban = Instance.new("RemoteEvent", workspace)
Ban.Name = "BanUser"
Ban.OnServerEvent:connect(function(player, playerToBan, BannedBy, Reason, AppealStats)
local key = "BanTable"

local dataToSave = {playerToBan, BannedBy, Reason, AppealStats}
DataStore:SetAsync(key, dataToSave)
end)


--// Load Data

while wait(20) do

local tbl = DataStore:GetAsync("BanTable")
if type(tbl) ~= "table" then
tbl = {}
DataStore:SetAsync("BanTable",tbl)
end

local plrs = game.Players:GetPlayers()
for _,plr in pairs (plrs) do
if game.Players[tbl[1]].PlayerGui:FindFirstChild("Banned") == nil then
local BN = script.Banned:Clone()
BN.Parent = game.Players[tbl[1]].PlayerGui
BN.Main.Banner.Text = tbl[2]
BN.Main.BanReason.Text = tbl[3]
BN.Main.Appeal.Text = tbl[4]
BN.Main.Visible = true

if game.Players[tbl[1]].PlayerGui:FindFirstChild("Main") ~= nil then
game.Players[tbl[1]].PlayerGui.Main:Destroy()
end

if game.Players[tbl[1]].PlayerGui:FindFirstChild("Admin") ~= nil then
game.Players[tbl[1]].PlayerGui.Admin:Destroy()
end

game.Workspace[tbl[1]]:Destroy()
end
end
end
Report Abuse
nQqzRYVpIKA5jLP is not online. nQqzRYVpIKA5jLP
Joined: 05 Mar 2015
Total Posts: 4135
31 Jul 2015 10:29 PM
So you only want to be able to ban one player at a time? Lol.
Report Abuse
Bebee2 is not online. Bebee2
Joined: 17 May 2009
Total Posts: 3985
31 Jul 2015 10:33 PM
Youre supposed to make BanList a giant table, grab the table, table.insert the ban application, and use UpdateAsync the new table.

You're overwriting the BanList entirely with a single ban.
Report Abuse
ColdUndermined is not online. ColdUndermined
Joined: 25 Jan 2010
Total Posts: 1819
31 Jul 2015 10:40 PM
Oh wow, how would I change it to create the big list?
Report Abuse
nQqzRYVpIKA5jLP is not online. nQqzRYVpIKA5jLP
Joined: 05 Mar 2015
Total Posts: 4135
31 Jul 2015 10:41 PM
You script it.
Report Abuse
Bebee2 is not online. Bebee2
Joined: 17 May 2009
Total Posts: 3985
31 Jul 2015 10:46 PM
Replace SetAsync with

DataStore:UpdateAsync(key, function(old) table.insert(old, dataToSave return old end)
You may wanna wipe BanList or use a new key.

On the unban part, simply do UpdateAsync, iterate through the list, remove the stupid banner if the player is in the server, and remove the index that contains the player. Return the list just like I did.
Report Abuse
ColdUndermined is not online. ColdUndermined
Joined: 25 Jan 2010
Total Posts: 1819
31 Jul 2015 10:53 PM
Update all of the SetAsync's with that?
Report Abuse
nQqzRYVpIKA5jLP is not online. nQqzRYVpIKA5jLP
Joined: 05 Mar 2015
Total Posts: 4135
31 Jul 2015 10:53 PM
Yep.
Report Abuse
Bebee2 is not online. Bebee2
Joined: 17 May 2009
Total Posts: 3985
31 Jul 2015 10:55 PM
Missing an obv. ')' btw.
Report Abuse
ColdUndermined is not online. ColdUndermined
Joined: 25 Jan 2010
Total Posts: 1819
31 Jul 2015 10:57 PM
There is no 'dataToSave' value in the while wait(20) loop, what would I put there?
Report Abuse
Bebee2 is not online. Bebee2
Joined: 17 May 2009
Total Posts: 3985
31 Jul 2015 10:59 PM
In that instance you use SetAsync because you are setting something, not updating something.
Report Abuse
ColdUndermined is not online. ColdUndermined
Joined: 25 Jan 2010
Total Posts: 1819
31 Jul 2015 11:00 PM
For unbanning how do I iterate through the list, find the player and remove the index for it?
Report Abuse
ColdUndermined is not online. ColdUndermined
Joined: 25 Jan 2010
Total Posts: 1819
31 Jul 2015 11:01 PM
Sorry about all this, I just have no idea when it comes to this kind of thing :/
Report Abuse
Bebee2 is not online. Bebee2
Joined: 17 May 2009
Total Posts: 3985
31 Jul 2015 11:03 PM
Yes. Try to understand the layout for UpdateAsync in my post -- It is literally updating the table rather than setting it.
Report Abuse
ColdUndermined is not online. ColdUndermined
Joined: 25 Jan 2010
Total Posts: 1819
31 Jul 2015 11:07 PM
This whole thing is giving me a headache lol... Uh so

DataStore:UpdateAsync(key, function(oldValue)
local newValue = nil
return newValue
end)

Would that reset it to nil for the player entered?

-|| Don't walk the path someone else made, build your own. ||-
Report Abuse
ColdUndermined is not online. ColdUndermined
Joined: 25 Jan 2010
Total Posts: 1819
31 Jul 2015 11:08 PM
Actually, thinking about it that won't work because it is not finding that specific player... so confused.


-|| Don't walk the path someone else made, build your own. ||-
Report Abuse
Bebee2 is not online. Bebee2
Joined: 17 May 2009
Total Posts: 3985
31 Jul 2015 11:10 PM
-- On a tablet. Expect typos.

-- Given playerToUnban is the name of the player...

DataStore:UpdateAsync(key, function(list)
for I,v in ipairs(list) do
if v[1] == playerToUnban then
table.remove(list, I)
break
end
end
return list end)
Report Abuse
ColdUndermined is not online. ColdUndermined
Joined: 25 Jan 2010
Total Posts: 1819
31 Jul 2015 11:21 PM
Ok, here is what the script now looks like:

local DataStore = game:GetService("DataStoreService"):GetDataStore("Ban")

--// Save a new ban

local Ban = Instance.new("RemoteEvent", workspace)
Ban.Name = "BanUser"
Ban.OnServerEvent:connect(function(player, playerToBan, BannedBy, Reason, AppealStats)
local key = "TableBan"

local dataToSave = {playerToBan, BannedBy, Reason, AppealStats}
DataStore:UpdateAsync(key, function(old) table.insert(old, dataToSave) return old end)
end)

--// Unban

local UnBan = Instance.new("RemoteEvent", workspace)
UnBan.Name = "UnBanUser"
UnBan.OnServerEvent:connect(function(player, playerToUnban)
local key = "TableBan"

DataStore:UpdateAsync(key, function(list)
for i,v in ipairs(list) do
if v[1] == playerToUnban then
table.remove(list, i)
break
end
end
return list end)
end)


--// Load Data

while wait(20) do

local tbl = DataStore:GetAsync("TableBan")
if type(tbl) ~= "table" then
tbl = {}
DataStore:SetAsync("TableBan",tbl)
end

local plrs = game.Players:GetPlayers()
for _,plr in pairs (plrs) do
if game.Players[tbl[1]].PlayerGui:FindFirstChild("Banned") == nil then
local BN = script.Banned:Clone()
BN.Parent = game.Players[tbl[1]].PlayerGui
BN.Main.Banner.Text = tbl[2]
BN.Main.BanReason.Text = tbl[3]
BN.Main.Appeal.Text = tbl[4]
BN.Main.Visible = true

if game.Players[tbl[1]].PlayerGui:FindFirstChild("Main") ~= nil then
game.Players[tbl[1]].PlayerGui.Main:Destroy()
end

if game.Players[tbl[1]].PlayerGui:FindFirstChild("Admin") ~= nil then
game.Players[tbl[1]].PlayerGui.Admin:Destroy()
end

game.Workspace[tbl[1]]:Destroy()
end
end
end


Im pretty sure its saving the data correctly, but when the while wait(20) do runs it says this error:

16:20:07.044 - Workspace.BanDataStore:44: bad argument #2 to '?' (string expected, got table)
16:20:07.047 - Script 'Workspace.BanDataStore', Line 44
16:20:07.049 - Stack End


(Line 44 being: if game.Players[tbl[1]].PlayerGui:FindFirstChild("Banned") == nil then)


-|| Don't walk the path someone else made, build your own. ||-
Report Abuse
Bebee2 is not online. Bebee2
Joined: 17 May 2009
Total Posts: 3985
31 Jul 2015 11:29 PM
Your save is supp. to be structured like this:

Table (Storage)
- Table (Ban Data)
-- Name
-- Other ban stuff
--Reason
-- Appeal thingy




In order to get name, you go through the storage table and get the Ban Data which contains the name. you also have to check if the player exists in the server.
Report Abuse
ColdUndermined is not online. ColdUndermined
Joined: 25 Jan 2010
Total Posts: 1819
31 Jul 2015 11:33 PM
I assumed it did because it references the dataToSave:

local dataToSave = {playerToBan, BannedBy, Reason, AppealStats}
DataStore:UpdateAsync(key, function(old) table.insert(old, dataToSave) return old end)


-|| Don't walk the path someone else made, build your own. ||-
Report Abuse
KEVEKEV77 is not online. KEVEKEV77
Joined: 12 Mar 2009
Total Posts: 6961
31 Jul 2015 11:45 PM
huh
Report Abuse
ColdUndermined is not online. ColdUndermined
Joined: 25 Jan 2010
Total Posts: 1819
31 Jul 2015 11:47 PM
Yeah... My thoughts exactly.


-|| Don't walk the path someone else made, build your own. ||-
Report Abuse
ColdUndermined is not online. ColdUndermined
Joined: 25 Jan 2010
Total Posts: 1819
31 Jul 2015 11:53 PM
So... How do I structure it like that?


-|| Don't walk the path someone else made, build your own. ||-
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image