Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

How do i save the players that are banned from the game?

Asked by 4 years ago
Edited 4 years ago
01local DatastoreService = game:GetService("DataStoreService")
02local ds = DatastoreService:GetDataStore("BanList")
03local ReplicatedStorage = game:GetService("ReplicatedStorage")
04local event1 = ReplicatedStorage.AdminGui:WaitForChild("Ban")
05local event2 = ReplicatedStorage.AdminGui:WaitForChild("Unban")
06 
07local Players = game:GetService("Players")
08 
09local bannedpeople = {}
10 
11ds:GetAsync(bannedpeople)
12 
13game.Players.PlayerAdded:Connect(function(plr)
14    if table.find(bannedpeople, plr.UserId) then
15        wait(0.2)
View all 43 lines...

This question got edited, i wanna know if it's correct.

Please help me.

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

I'm really out of time, wrote this basic script which I am 100% will help, but basically, use only ONE key for the banned players, and also some code shortening using table.find:

01local dss = game:GetService("DataStoreService")
02local http = game:GetService("HttpService")
03local banStore = dss:GetDataStore("banStore")
04 
05local banned = {}
06 
07game.Players.PlayerAdded:Connect(function(player)
08 
09    pcall(function()
10 
11        banned = http:JSONDecode(banStore:GetAsync("banned"))
12 
13    end)
14 
15    if banned then
View all 37 lines...

Hope this helped! (even though i didn't really explain anything) Edit: added a function so you know how to add banned players.

0
what is the purpose of using jsonencode? why not just store the normal table information? Gey4Jesus69 2705 — 4y
1
Datastores only accept numbers and strings, and JSONEncode converts tables to strings. Hence why. However, from what I know, some time in the past they made it so it automatically converted it to json strings if you attempted to save tables to a datastore, but I still do it for a habit. User#32819 0 — 4y
1
Thanks, I was looking for this. User#33317 0 — 4y
0
yeah i was wondering bc i save tables to datastores all the time, but i suppose converting them yourself might be more efficient Gey4Jesus69 2705 — 4y
0
congrats a whole json encode decode system greatneil80 2647 — 4y
Ad

Answer this question