What do you want to achieve? Im making a system where if you click the player it gives you their info (name, account age, Role In Group, etc). Im having trouble with the name… sad, right? Im trying tons of different things but it doesn’t seem to be working.
What is the issue? It won’t work.
What solutions have you tried so far? YouTube videos.
This is my script
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local tool = script.Parent
local Frame = game.Players.LocalPlayer.PlayerGui:WaitForChild('ScreenGui'):WaitForChild('Frame') --Object path to the GUI frame containing the age and rank textboxes.
local groupID = 4796549 --ID of your group.
tool.Activated:Connect(function()
for _,Target in pairs(game.Players:GetPlayers()) do
if Mouse.Target:IsDescendantOf(Target.Character) then
Frame.Visible = true
Frame.AccAge.Text = Target.AccountAge
Frame.RoleInGroup.Text = Target:GetRoleInGroup(groupID)
Frame.Name.Text = Target.Name
wait(3)
Frame.Visible = false
end
end
end)
-- Make sure they can't use the tool while it is not selected.
tool.Unequipped:Connect(function()
Frame.Visible = false
end)
I’m pretty sure FindFirstChild whould work, but use this code to test a custom FindFirstChild:
local function FindFirstChild(Obj,Name)
local ReturnObj
for _,Object in ipairs(Obj:GetChildren()) do
if Object.Name == Name then
ReturnObj = Object
end
end
return ReturnObj
end
FindFirstChild(Frame,"Name").Text = Target.Name
You should just generally avoid naming children after properties. They’re bound to error, and FindFirstChild is a bit of a hacky fix for it. Naming the label something like DisplayName would suffice.