BanData not working

Hello, there! Why isn’t this script banning me?

Scripts:

No errors in the output.

Well in your Ban function, you gave nothing for the UserId, so the player is nil, secondly, you’re trying to use GetPlayerByUserId on a player instance? It’s a method of the players service

1 Like

I changed it to plr inside it.

Can you give me a fix of the whole function?

It depends on what you’re giving it, if you’re giving it a name, get the userid via GetNameFromUserIdAsync, a method of the Players Service, store the result in a variable and put that in set async

You’re probably not going to understand without an example, so here

local id = game:GetService("Players"):GetNameFromUserIdAsync(plr)

And use t hat

Okay. It’s do not work. The whole script:

Did you remember use the ban function? Also you do not add the true in GetAsync, you jsut need to give it the key

I did and alright. I will change it.

You are using :GetAsync() incorrectly, this function only requires one parameter which is the key the data is saved under. You should also add error handling and checks so your script doesn’t yield if problems arise when using datastores.

local DataStoreService = game:GetService("DataStoreService")
local ExampleDataStore = DataStoreService:GetDataStore("Example")

local GetAsync_Request = ExampleDataStore:GetAsync("Example_Key") 
-- Can also be called by itself without setting a variable, like with your if statement

I would suggest making your system run on the players UserId instead of their names since they can change, but your ID can not.

function FBan.Ban(Player)
     local UserId = Player.UserId
     FBan.BanStoring:SetAsync(UserId, true)
end
1 Like