Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to get a Players name by mouse.Target?

Asked by 10 years ago

What this script does is when you click on a player in a game it brings up a gui, that gui would be the players profile. Only one problem I don't know how to get the players name from the person they clicked.

I tried this but it did not seem to work. Title.Name = mouse.Target.Parent.Name .. "'s Profile"

The title should appear as "IntellectualBeing's Profile" (Using my name as an example)

wait(1)
local plr = game.Players.LocalPlayer;
local mouse = plr:GetMouse();
local Frame2 = script.Parent.Content
local Title = Frame2.Title

mouse.Button1Down:connect(function()
    if mouse.Target and mouse.Target.Parent and game.Players:GetPlayerFromCharacter(mouse.Target.Parent) then 
        Frame2.Visible = true; 
        Title.Name = mouse.Target.Parent.Name .. "'s Profile" --This does not work.
    end
end)

3 answers

Log in to vote
0
Answered by
Nickoakz 231 Moderation Voter
10 years ago

Sometimes your script would not work because first. What if the mouse target was a part inside a hat? We need to make sure we are getting the character. So this one below should work. Also, I don't think numbers inside variable names will not work.

wait()
local plr = game.Players.LocalPlayer;
local mouse = plr:GetMouse();
local FrameB = script.Parent.Content --I think numbers in variables wont work. Try letters instead.
local Title = FrameB.Title
mouse.Button1Down:connect(function()
    if mouse.Target and mouse.Target.Parent then
        plr=game.Players:GetPlayerFromCharacter(mouse.Target.Parent) 
        if plr~=nil then 
            FrameB.Visible = true
            Title.Text = plr.Name .. "'s Profile" --Works now.
        else
            plr=game.Players:GetPlayerFromCharacter(mouse.Target.Parent.Parent) 
            if plr~=nil then 
                FrameB.Visible = true
                Title.Text = plr.Name .. "'s Profile" --Works now.
            else
                plr=game.Players:GetPlayerFromCharacter(mouse.Target.Parent.Parent.Parent)
                if plr~=nil then 
                    FrameB.Visible = true
                    Title.Text = plr.Name .. "'s Profile" --Works now.
                end 
            end 
        end
    end
end)

Edit: What if you hit a hat, Thats double in the input.

1
Thank's for making my code more efficient! :) IntellectualBeing 430 — 10y
0
Wait, it's not changing the title text? IntellectualBeing 430 — 10y
1
You have it set to change the name of the title. Edited it to change the Title text. Nickoakz 231 — 10y
Ad
Log in to vote
-1
Answered by
Tkdriverx 514 Moderation Voter
10 years ago

(I can't comment on other answers): @1518NICENICKEY: You can have numbers in the variables as long as the number isn't at the beginning of the variable name.

And, I believe you have a great fix for it. Same idea I had when I saw this.

0
Thanks. I know, it sucks when you cant post a comment on other users posts until your reputation is above 10. Nickoakz 231 — 10y
Log in to vote
-2
Answered by 10 years ago

it goes like this

wait(1)
local plr = game.Players.LocalPlayer;
local mouse = plr:GetMouse();
local Frame2 = script.Parent.Content
local Title = Frame2.Title

mouse.Button1Down:connect(function()
    if mouse.Target and mouse.Target.Parent and game.Players:GetPlayerFromCharacter(mouse.Target.Parent) then 
        Frame2.Visible = true; 
        Title.Name = mouse.Target.Parent.Name .. "usernames's Profile" --This does not work.
    end
end)


0
I am just trying to get the name of the player that they clicked on. IntellectualBeing 430 — 10y
0
yes in scripting "username" stand for that persons username like "teleport username to chat=sayer.end danielsarabia11 -2 — 10y
0
Well, not really. If I used that for this.. Part.Name = OtherPart.Name .. "username's Profile" It would return "Partusername'sProfile" IntellectualBeing 430 — 10y
1
I'm sorry, daniel. But you have no idea how scripts work. You put "username's" in a string, so it will show "Partusername's Profile". Besides, did you even try to make a script like this? Was it disastrous? Nickoakz 231 — 10y

Answer this question