Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Advanced Ways to get player name?

I am making a script that gives access to a GUI if their username matches one of my admins. We wanted to make it from scratch. We have something like this.


local allowed1 = "6kCrxzy"
local allowed2 = "alex23x42"
local allowed3 = "iiTheLastBacon"
local plr = game.Players.LocalPlayer
local name = plr.name
local gui = game.StarterGui.AdminPanel

if name == allowed1 or allowed2 == name or allowed3 == name then
    gui.Visible = true
    else 
        gui:Destroy()
        end
   

I know how unsecure this is and how I should do this with a server side script and clone it from Replicated Storage and all that. I like local scripts and I am gonna stick with them. If you can help me, please tell me the best and most secure way to get a player's name, one that is hard to spoof. I know you can check the game.Players.LocalPlayer.Name or game.Players.LocalPlayer.Character.Name. but those can be easily spoofed with a exploiter changing the client values. Can anyone tell me how to get a players name, one that is a challenge to spoof. Thanks!

2 comments

0

use the server side..(?)

0

Create a table with an array of UserIds (do not use player usernames because they can change their username for 1000 R$) and loop if a particular number is similar to the player's UserId (FirewolfYT_751's method), and use ServerScriptService for server-side scripts.

3 answers

Like Heavenlyblobmaster said, use server side, you can do something like:

local allowed1 = "6kCrxzy"
local allowed2 = "alex23x42"
local allowed3 = "iiTheLastBacon"
game.Players.PlayerAdded:Connect(function(Player) 
	local name = Player.Name
	if name == allowed1 or allowed2 or allowed3 then
		--give them admin
	end
end)

First of all, you should use a table, then go through, see if yada yada yada

local allowed = {"6kCrxzy", "alex23x42", "iiTheLastBacon"}

game.Players.PlayerAdded:Connect(function(p)
	local username = p.Name
	for i, plr in pairs(allowed) do
		if username == plr then
			-- do stuff to give them admin
		end
	end
end)

If you need any more help, let me know.

The first answer is wrong, and the second answer can be shortened to this:

local allowed = {
	["6kCrxzy"] = true,
	["alex23x42"] = true, 
	["iiTheLastBacon"] = true,

	-- REPLACE THESE WITH THEIR IDS
	-- example below of how a UserId setup would look like
	[12345678] = true
}

game:GetService("Players").PlayerAdded:Connect(function(plr)
	if not allowed[plr.UserId] then
		print("UserId not whitelisted")
	else
		print("UserId whitelisted")
		-- execute the rest of the code
	end
end)

I'd also like to heavly recommend using UserId instead of Name, since the UserId is completely unique whereas the name can be changed at later times. (you can find a player's UserId in the URL of their roblox profile)

So what should you know now?

  • Verify on the server
  • Use a simple table setup to check the player
  • Use Player.UserId over Player.Name

Following all three gives you a player check that cannot at all be spoofed, unless you handle the rest of the code badly.

This discussion is preserved as it was. New answers, comments, and votes are closed.