Hey, I’ve recently encountered a problem regarding my security scanner and I am wondering how I would access a user’s username & userId from a humanoid. like if a player walks through a part it will get the player’s username & userId maybe by a touch event?
1 Like
Something like
Players:GetPlayerFromCharacter(humanoid.Parent)
2 Likes
local Players = game:GetService("Players")
local part = script.Parent
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local hum = hit.Parent:FindFirstChild("Humanoid")
local player = Players:GetPlayerFromCharacter(humanoid.Parent)
local playerName = player.Name
local userID = player.UserId
end
end
If you want to save that value, you could do make two stringvalues and set its Value to the playername and userID
local Players = game:GetService("Players")
local part = script.Parent
local stringvalueID = script.Parent.UserIdValue
local stringplayerName = script.Parent.PlayerNameValue
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local hum = hit.Parent:FindFirstChild("Humanoid")
local player = Players:GetPlayerFromCharacter(humanoid.Parent)
local playerName = player.Name
local userID = player.UserId
stringplayerName = playerName
stringvalueID.Value = userID
end
end
local players = game:GetService('Players')
local part = -- idk
part.Touched:Connect(function(object)
local hum = object.Parent:FindFirstChild('Humanoid')
if hum then
local s, r = pcall(function()
return players:GetPlayerFromCharacter(hum.Parent)
end
if s and typeof(r) == "Instance" then
print(r.Name) -- yes boys we got it
end
end
end)
1 Like