✓ Accepted answer
A few things to note about your code:
• You've already define PlayersName, so just use PlayersName (instead of BallTarget.PlayersName). Also, you should be setting properties like Text like so: PlayersName.Text
• Assuming Name is a property, you only need to do .Name. Also, you don't need .Text after the name. You do need that for setting the text in PlayersName, however.
• You should include a check to see if the player is actually a player. You can do this by using GetPlayerFromCharacter.
• You defined BallTarget twice, you only need to define a variable once. Also, you can reference variables that are previously made in your script when setting other variables (assuming the referenced variable is global or in the same scope.)
• Finally, you should use this in a normal Script in the BallTarget brick/union so that the Touched event works correctly.
Following the advice above, your code should look like this:
local BallTarget = script.Parent
local PlayersName = BallTarget.BillboardGui.PlayersName
BallTarget.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(hit.Parent) then
PlayersName.Text = hit.Parent.Name
end
end)
I hope my answer helped you. If it did, be sure to accept it.