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

Getting player name and putting it into TextBox?

I have a part in Workspace named Part and inside it is a script, I want that script to on touched get the player's name that has just touched the part and put their name in a GUI

local playername = game.StarterGui.checkinGui.mainFrame.playerName
local plrname = game.Players.LocalPlayer

function onTouch()
	playername = plrname.Name
end

script.Parent.Touched:connect(onTouch)

Using a normal Script btw, not a LocalScript.

5 comments

0

Well what do I put then?

0

Wiki Description: "This property is client-side only! You should use a LocalScript instead of a Script when using it."

0

I would use a local script to do this, and then fire a server event the changes the name, and then it already has the value of player in the server script.

3 answers

The way to do this via ServerScript would be :GetPlayerFromCharacter() which does exactly what you would think it does, gets the player from a character.

--in a ServerScript
script.Parent.Touched:connect(function(part)
	local maybePlayer = game.Players:GetPlayerFromCharacter(part.Parent)
	if maybePlayer then --if it's a player
		local name = maybePlayer.Name
		--other stuff here
	end
end)

Not 100% sure this will work and may require some tweaking to your situation, but this is what I got.

--Here is the local script running ON YOUR PERSON
    local Event = repStorage:WaitForChild("YourRemoteEvent")
    part.Touched:connect(function(hit)

if hit.Parent == game.Players.LocalPlayer then
Event:FireServer(hit.Parent)
end



    end)


--Here is the server script
local Event = repStorage:WaitForChild("YourRemoteEvent")
Event.OnServerEvent:connect(function(player, hit)


NavigateToWhereTheTextIs.Text = hit


end)

Like I said, you need to tweak it a little bit, but I think it SHOULD work. I didn't test it so if it doesn't try your best to figure it out, or just reply asking.

2 comments

0

Um, you say if hit == LocalPlayer, do you mean LocalPlayer.Character? Also, I believe hit would be a part of the players character. And one last thing, you set .Text equal to a basePart (which is what hit should be)

0

I fixed it, thanks theCJarmy7

Try This:

--Thanks jamiethegreatQ777 For Making This :)
Credit To jamiethegreatQ777 = true
if Credit To jamiethegreatQ777 == false then return end
game.Workspace.part.SurfaceGui.TextBox.Text = game.players.Localplayer "..PlayerName.."

I'm Sure This Will Work If Not Please Message Me twitter.com/jamiethegreatQ7

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