I am trying to make a ban datastore that takes in some value from an admin console GUI. The admin console is designed to ban players based off of their username. After digging around devforum, I noticed that datastores require a player’s predefined ID. More specificly:
player.UserId -- in my case its 609345911
My data store script (partial):
local DataStoreService = game:GetService("DataStoreService")
local BanDataStore = DataStoreService:GetDataStore("BanDataStore")
game.ReplicatedStorage.BanPlayer.OnServerEvent:Connect(function(player, username)
BanDataStore:SetAsync(username.UserId, true)
end)
game.ReplicatedStorage.UnbanPlayer.OnServerEvent:Connect(function(player, username)
BanDataStore:SetAsync(username.UserId, false)
end)
It currently throws an error because the username of that player is not indexed properly. I want to change my script to this:
local DataStoreService = game:GetService("DataStoreService")
local BanDataStore = DataStoreService:GetDataStore("BanDataStore")
game.ReplicatedStorage.BanPlayer.OnServerEvent:Connect(function(player, username)
BanDataStore:SetAsync(game.Players[username.Name].UserId, true) -- notice: this line changed
end)
game.ReplicatedStorage.UnbanPlayer.OnServerEvent:Connect(function(player, username)
BanDataStore:SetAsync(username.UserId, true)
end)
It also throws an error because the player that I am trying to ban is not in the game. Therefore, the server cannot find the specified username. Is there a way to ban with a username or does it have to be player ID? Second question: If I have to use player’s ID to ban them, how to I find some player’s ID? (ik that i can search their username up, but some usernames are obscure and will result in ###########)