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

How do I get the name of the player who touched a block?

Asked by 9 years ago

I am completely confused. I put a '?' in the spot where I don't know what to put.

function claim()
    script.Parent.Parent.OwnerName.SurfaceGui.Owner.Text = "Owned by: "..?.."" -- What do I put where the '?' is?
end

script.Parent.Touched:connect(claim)

1 answer

Log in to vote
1
Answered by 9 years ago

Try this

script.Parent.Touched:connect(function(hit)
    if game.Players:GetPlayerFromCharacter(hit.Parent) then
        script.Parent.Parent.OwnerName.SurfaceGui.Owner.text = "Owned by: "..hit.Parent.Name
    end
end)

Here we: - Define the function in the event, to save space. - Make the argument hit inside the function, with the Touched event the only argument is the thing that touched it. - Check to make sure the parent of what touched it is a Player - If the thing that touched it is a child of a Player, then it makes the text have that name in it

If this helped remember to make it the correct answer, thank you, and you're welcome. :)

1
That worked perfectly except you had 1 capitalization issue. The 'text' in string 3 need's to be capitalized, just for future reference. SchonATL 15 — 9y
0
Capitalization error.. line 3 Goulstem 8144 — 9y
0
Sorry about that, everything else was fine so that's cool. Norshine 88 — 9y
Ad

Answer this question