Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make sure that when the player touches a share his name is written in a text label?

My script:(I put it in a local script)

local Part = script.Parent

Part.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local PlayerName = hit.Parent.Name

		script.Parent.Parent.Parent.StarterGui.ScreenGui.TextLabel.Text = PlayerName
	end
end)

1 answer

✓ Accepted answer

wrong, this is a very common mistake which a lot of people edits screengui, yeah that works before but it's moved to playergui (located inside game.Players.LocalPlayer)

you are going to do:

local Part = script.Parent

Part.Touched:Connect(function(hit)
    if hit.Parent.Name == game:GetService("Players").LocalPlayer.Name and hit.Parent:FindFirstChild("Humanoid") then
        local Character = hit.Parent -- Usually we get the character, not name
	local PlayerGui = game:GetService("Players").LocalPlayer.PlayerGui

        PlayerGui:WaitForChild("ScreenGui").TextLabel.Text = Character.Name
    end
end)

3 comments

0

this might be a little confusing but in the if-then statement, i have made two statements, the first one is what i changed, it detect if the touched player name is equaled to localplayer name

0

the reason i located playergui is because script too long lol

0

thanks it works!

This discussion is preserved as it was. New answers, comments, and votes are closed.