I’m making a border game right now, its going well so far. But i wanted to know how to find out how to mark down the players username, account age, and group rank when a part is touched. This information would be displayed on a surface gui. For right now, i just want to display the players name when a part is touched. How would u do that?
1 Like
You can use GetPlayerFromCharacter and assign it to a variable inside the touched event function:
local Players = game:GetService("Players")
part.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if not player then return end
-- your code here
end)
you can get the player’s name by player.Name
, and account age by player.AccountAge
and rank by player:GetRankInGroup(groupid)
. so, you would wrap it up in a script like this:
local Players = game:GetService("Players")
local part = script.Parent
local surfaceGui = part:FindFirstChild("InfoDisplay")
local NameLabel = surfaceGui:FindFirstChild("PlayerNameLabel")
local accountAgeLabel = surfaceGui:FindFirstChild("AccountAgeLabel")
local RankLabel = surfaceGui:FindFirstChild("GroupRankLabel")
local groupId = 0 -- your group ID
part.Touched:Connect(function(hit)
local character = hit.Parent
local player = Players:GetPlayerFromCharacter(character)
if player then
NameLabel.Text = "Player: " .. player.Name
accountAgeLabel.Text = "Account Age: " .. player.AccountAge .. " days"
local rank = player:GetRankInGroup(groupId)
RankLabel.Text = "Group Rank: " .. rank
end
end)
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.