User Info Scanner Display

Hello there!
I’m trying to make a security checkpoint where when a player walks through the gates, a display nearby shows their user id and name. How would I detect the player’s info when it is touched?

Here’s what I have so far:

script.Parent.Touched:Connect(function(p)
local humanoid = p.Parent:FindFirstChild("Humanoid")
if humanoid then 

local var = game.Workspace.Part.SurfaceGui.Frame.TextLabel
var.Text = "Add here" 

end 

end)
1 Like

You can use the :GetPlayerFromCharacter() function.

An example of this in use

local PS = game:GetService("Players");

script.Parent.Touched:Connect(function(Hit)
	local Player = PS:GetPlayerFromCharacter(Hit.Parent);
	if Player then  -- Make sure it exist and isn't nil
		print(Player.UserId);
		-- do whatever else, etc
	end;
end);
1 Like
script.Parent.Touched:Connect(function(p)
   local Player = game.Players:GetPlayerFromCharacter(p.Parent) or game.Players:GetPlayerFromCharacter(p.Parent.Parent)
   game.Workspace.Part.SurfaceGui.Frame.TextLabel.Text = Player.UserId.." - "..Player.Name
end)
1 Like

I hope this works

local debounce = false

script.Parent.Touched:Connect(function(p)
	local humanoid = p.Parent:FindFirstChild("Humanoid")
	if humanoid and not debounce then
		debounce = true
		local plr = game:GetService("Players"):GetPlayerFromCharacter(p.Parent)
		
		local var = game.Workspace.Part.SurfaceGui.Frame.TextLabel
		var.Text = "Player Name:".. plr.Name .." UserId: ".. plr.UserId
		
		wait(5)
		debounce = false
	end 
end)
1 Like