Getting The Banned Player UserId Without Needing them On Your Server

i know i fixed the ban ui but i needed just one tiny help.

how would i get a player’s userid globally?

i know :GetUserIdByNameASync() is a thing but i wanna implement it

heres the script where i wanna place it on

local ps = game:GetService("Players")


function convertDaysToSecends(days)
	return 86400 * tonumber(days)
end


function convertHoursIntoSecends(hours)
	return 3600 * tonumber(hours)
end

local AllowedPeople = {
	1813216757,
	1915724787,
	1029123331,
	2728185622,
}



game.ReplicatedStorage["Banny_Binny!"].OnServerEvent:Connect(function(player, bannedplr, banrsn, bandur)
	if not table.find(AllowedPeople, player.UserId) then return end
	print(tonumber(bandur))
	bannedplr = ps:FindFirstChild(bannedplr)
	if not bannedplr then warn("no player!") return nil end
	local config: BanConfigType = {
		UserIds = {bannedplr.UserId}, -- where i wanna place it
		Duration = tonumber(bandur),
		DisplayReason = banrsn,
		PrivateReason = bannedplr.Name.." got banned because of: "..banrsn,
		ExcludeAltAccounts = false,
		ApplyToUniverse = true
	}


	local success, errorMessage = pcall(function()
		return ps:BanAsync(config)
	end)
	if success then
		for i, v in config do
			print(i, v)
		end
	else
		warn(errorMessage)
	end
end)

so I take it you want to get the AllowedPeople from like anywhere?
if so you’re best bet is using a module to store all the IDs.

if thats not what you meant please correct me~
~ Frodev

so i just replace the entire script into a module script?

no, just the list of Ids, unless you want to be able to access your functions from any where.
To help give an understanding heres a post on modules that will hopefully help!

i didnt mean the allowed people part i meant to ban players when they are. offline. in a diffrent game. in a diffrent server. and so on

Ohhh well then instead of sending the bannedPlr as a player, maybe send it as the players UserId.
Then they wouldnt need to be in the server

sorry i didnt understood

i think you meant this

bannedplr = ps:FindFirstChild(bannedplr.UserId)
1 Like

no I mean this, when you send bannedplr to the server, it well, its a player from the look of things, thus, instead, you should send bannedplr as a UserId.

i think it will work but one issue

im trying to convert the player string into a userid

whats a “player string”? Like the players name?

yeah exactly but the player’s name is a string

ahhh I see.
Well in that case you can use this:

It takes the name and gives you the UserId

How do you actually get the player on client?
And i wouldn’t suggest banning by the name, the player can change their user and bypass your ban?

they arent banning them via name, robloxs ban async seems to only take UserIds, not to mention in there code you can see they do in fact put the UserId in there, not the name so yeah.

i tried doing everything to make it global but it seems like i couldnt do anything. ill be back once i figure out how to actually get the player’s userid to be global

I did read this and thought he is going to use the name, and i never used the roblox ban async so i didn’t know but thanks for telling me

1 Like

can I just see your code? Cause from what your explaining, and not to be rude, dont think youre doing it correctly.

1 Like

nevermind guys i finally figured it out.
all i had to do is to change the bannedplr = ps:FindFirstChild(bannedplr) into

bannedplr = ps:GetUserIdFromNameAsync(bannedplr)

thanks for the help even though i figured it out by myself

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.